标签:cout div string lse style eof 强连通分量 algorithm als
http://poj.org/problem?id=3180
//#include<bits/stdc++.h> #include<iostream> #include<cstdio> #include<iomanip> #include<cmath> #include<algorithm> #include<vector> #include<cstring> #include<queue> #include<map> #include<string> #include<stack> #define fi first #define se second #define INF 0x3f3f3f3f #define fio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0) #define pqueue priority_queue #define NEW(a,b) memset(a,b,sizeof(a)) #define lowbit(x) ((x)&(-x)) const double pi=4.0*atan(1.0); const int maxn=1e5+8; typedef long long LL; typedef unsigned long long ULL; const LL mod=1e9+7; const ULL base=1e7+7; using namespace std; struct node{ int to,nxt; }g[maxn*2]; int head[maxn]; int cnt=0; void add(int u,int v){ g[cnt].to=v; g[cnt].nxt=head[u]; head[u]=cnt++; } int deep=0; int dfn[maxn],low[maxn]; bool vis[maxn]; int Stack[maxn]; int tail=0; int ans=0; void tarjan(int u){ dfn[u]=++deep; low[u]=deep; Stack[++tail]=u; vis[u]=1; int t=head[u]; int r=0; while(t!=-1){ if(!dfn[g[t].to]){ tarjan(g[t].to); low[u]=min(low[u],low[g[t].to]); } else{ if(vis[g[t].to]){ low[u]=min(low[u],low[g[t].to]); } } t=g[t].nxt; } if(dfn[u]==low[u]){ while(Stack[tail]!=u){ vis[Stack[tail]]=0; tail--; r=1; } vis[Stack[tail]]=0; tail--; } ans+=r; } int main(){ memset(head,-1,sizeof(head)); int n,m,x,y; scanf("%d%d",&n,&m); for(int i=1;i<=m;i++){ scanf("%d%d",&x,&y); add(x,y); } for(int i=1;i<=n;i++){ if(!dfn[i]){ tarjan(i); } } cout<<ans<<endl; }
标签:cout div string lse style eof 强连通分量 algorithm als
原文地址:https://www.cnblogs.com/Profish/p/10421559.html