标签:kosaraju scan string amp can str include == log
代码:
1 #include<cstdio> 2 #include<cstring> 3 #include<iostream> 4 using namespace std; 5 int maps[1100][1100],nmap[1100][1100]; 6 int vis[1001]; 7 int ans=0,aaa=0,n,m,post[1100]; 8 void dfs(int); 9 void ndfs(int); 10 int main() 11 { 12 scanf("%d%d",&n,&m); 13 for(int i=1;i<=m;i++){ 14 int x,y; 15 scanf("%d%d",&x,&y); 16 maps[x][y]=1; 17 nmap[y][x]=1; 18 } 19 for(int i=1;i<=n;i++) 20 { 21 if(vis[i]==0) 22 dfs(i); 23 } 24 for(int i=n;i>=1;i--) 25 { 26 if(vis[post[i]]==1) 27 { 28 ndfs(post[i]); 29 ans++; 30 } 31 } 32 cout<<ans; 33 } 34 void ndfs(int x) 35 { 36 vis[x]=0; 37 for(int i=1;i<=n;i++) 38 { 39 if(vis[i]&&nmap[x][i]==1) 40 ndfs(i); 41 } 42 } 43 void dfs(int x) 44 { 45 vis[x]=1; 46 for(int i=1;i<=n;i++) 47 { 48 if(!vis[i]&&maps[x][i]==1){ 49 dfs(i); 50 } 51 } 52 aaa++; 53 post[aaa]=x; 54 }
标签:kosaraju scan string amp can str include == log
原文地址:http://www.cnblogs.com/sssy/p/6693999.html