# [BZOJ1051][HAOI2006]受欢迎的牛

### [BZOJ1051][HAOI2006]受欢迎的牛

#### 输入示例

3 3
1 2
2 1
2 3


#### 输出示例

1


#### 数据规模及约定

$100\texttt{%}$ 的数据 $N \le 10000,M \le 50000$

#### 题解

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <algorithm>
using namespace std;
#define rep(i, s, t) for(int i = (s); i <= (t); i++)
#define dwn(i, s, t) for(int i = (s); i >= (t); i--)

int x = 0, f = 1; char c = getchar();
while(!isdigit(c)){ if(c == '-') f = -1; c = getchar(); }
while(isdigit(c)){ x = x * 10 + c - '0'; c = getchar(); }
return x * f;
}

#define maxn 10010
#define maxm 50010

int n;

struct Graph {
void AddEdge(int a, int b) {
return ;
}
} G, D;

int clo, dfn[maxn], low[maxn], cnts, scno[maxn], siz[maxn], S[maxn], top;
void dfs(int u, int fa) {
dfn[u] = low[u] = ++clo;
S[++top] = u;
for(int e = G.head[u]; e; e = G.nxt[e]) if(G.to[e] != fa) {
if(scno[G.to[e]]) continue;
if(dfn[G.to[e]]) low[u] = min(low[u], dfn[G.to[e]]);
else dfs(G.to[e], u), low[u] = min(low[u], low[G.to[e]]);
}
if(low[u] == dfn[u]) {
cnts++;
while(S[top] != u) scno[S[top--]] = cnts, siz[cnts]++;
scno[S[top--]] = cnts; siz[cnts]++;
}
return ;
}

int ideg[maxn], Q[maxn], hd, tl;
bool can[maxn];
void BFS(int s) {
can[s] = 1;
hd = tl = 0; Q[++tl] = s;
while(hd < tl) {
int u = Q[++hd];
for(int e = D.head[u]; e; e = D.nxt[e])
if(!can[D.to[e]]) can[D.to[e]] = 1, Q[++tl] = D.to[e];
}
return ;
}

int main() {
rep(i, 1, M) {
}

rep(i, 1, n) if(!scno[i]) dfs(i, 0);
rep(u, 1, n)
for(int e = G.head[u]; e; e = G.nxt[e]) if(scno[G.to[e]] != scno[u]) {