https://www.luogu.org/problem/P2341 缩点之后唯一 一个出度为0的点 #include<cstdio> #include<iostream> using namespace std; #define N 10001 #define M 50001 int front[N],nxt[M],to[M],tot; int dfn[N],low[N],st[N],top,bl[N],siz[N]; bool vis[N]; int out[N]; void…
http://poj.org/problem?id=2186 || https://www.luogu.org/problem/show?pid=2341 Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 33470 Accepted: 13634 Description Every cow's dream is to become the most popular cow in the herd. In a herd…
BZOJ原题链接 洛谷原题链接 显然在一个强连通分量里的奶牛都可以相互喜欢,所以可以用\(tarjan\)求强连通并缩点. 要求明星奶牛必须被所有人喜欢,显然缩点后的图必须满足只有一个点没有出度,因为若有两个点没有出度,那么其中一个点所包含的奶牛显然不能喜欢另一个点的奶牛. 而这个唯一的没有出度的点所包含的奶牛都可以成为明星奶牛. #include<cstdio> using namespace std; const int N = 1e4 + 10; const int M = 5e4 +…
受欢迎的牛 题目描述 一些可以当明星的牛,一定会构成一个强连通分量,我们可以先缩点,最后统计一下出度为零的强连通分量大小即可, 若出度为零的强连通分量个数大于1,则输出0 #include<iostream> #include<cstring> #include<cstdio> using namespace std; #define N 10010 #define M 100010 int n,m,dfn[N],low[N],belong[N],du[N],cnt;…
把强连通分量缩点,如果有且仅有一个出度为0的强连通分量,那么答案就是他的size:如果有多个入度为0的,那么没有明星牛. #include<cstdio> #include<iostream> #define R register int using namespace std; inline int g() { R ret=; register char ch; while(!isdigit(ch=getchar())); +(ch^); while(isdigit(ch=get…