tarjan板子
const int N = 10010, M = 100010;
int n, m;
int h[N], e[M], ne[M], idx;
int dfn[N], low[N], timestamp;
int stk[N], top;
bool in_stk[N];
int id[N], scc_cnt, Size[N];
void tarjan(int u){
dfn[u] = low[u] = ++ timestamp;
stk[ ++ top] = u, in_stk[u] = true;
for (int i = h[u]; ~i ;i = ne[i]){
int j = e[i];
if (!dfn[j]){
tarjan (j);
low[u] = min (low[u], low[j]);
}
else if(in_stk[j])
low[u] = min (low[u], dfn[j]);
}
if(low[u] == dfn[u]){
++ scc_cnt;
int y;
do{
y = stk[top --];
in_stk[y] = false;
id[y] = scc_cnt;
Size[scc_cnt] ++;
} while(y != u);
}
}