Water problem, direct sticker code.
POJ 3180//sep9#include <iostream> #include <stack>using namespace std;const int Maxn=10024;const int maxm= 50048;int Sum[maxn];int HEAD[MAXN],DFN[MAXN],LOW[MAXN],INS[MAXN],BELONG[MAXN]; stack<int> s;struct edge{int V,next;} Edge[maxm];int n,m,e,t,cnt;void Tarjan (int u) {dfn[u]=low[u]=++t;s.push (U); ins[u]=1;for (int i=head[u];i!=-1;i=edge[ I].next) {int v=edge[i].v;if (dfn[v]==0) {Tarjan (v); Low[u]=min (Low[u],low[v]);} else if (ins[v]==1) low[u]=min (Low[u],dfn[v]);} int k;if (Low[u]==dfn[u]) {++cnt;do{k=s.top (); S.pop (); ins[k]=0;belong[k]=cnt;} while (Low[k]!=dfn[k]);} return;} int main () {int n,m;scanf ("%d%d", &n,&m); e=0; memset (head,-1,sizeof (head)); memset (dfn,0,sizeof (DFN)); memset (ins,0,sizeof (INS)); while (m--) {int a,b;scanf ("%d%d", &a,&b); edge[e].v=b;edge[e].next=head[a];head[a]=e++;} t=cnt=0;for (int i=0;i<n;++i) if (!dfn[i]) Tarjan (i); memset (sum,0,sizeof (sum)); for (int i=0;i<n;++i) ++sum[belong[i]];int ans=0;for (int i=1;i<=cnt;++i) if (Sum[i] >1) ++ans;printf ("%d", ans); return 0;}
POJ 3180 The Cow Prom strong connectivity Component