201709-4通信网络
作者:互联网
#include<bits/stdc++.h> //#define test using namespace std; int mapp[1001][1001]; int visited[1001]; int n,m; int nownum; int ava[1001][1001]; int dfs(int a){ if(visited[a]) return 0; ava[nownum][a]=1; ava[a][nownum]=1;//这里改成双向修改就通过了! visited[a]=1; for(int i=1;i<=n;i++){ if(mapp[a][i]) dfs(i); } //visited[a]=0; } int main(){ cin>>n; cin>>m; int i,x,y; for(i=0;i<m;i++){ cin>>x; cin>>y; mapp[x][y]=1; } for(i=1;i<=n;i++){ for(int j;j<=n;j++){ ava[i][j]=0; } memset(visited,0,sizeof(visited)); nownum=i; ava[i][i]=1; //visited dfs(i); } bool s[1001]; y=0; x=0; int j; #ifdef test for(i=1;i<=n;i++){ for(j=1;j<=n;j++){ cout<<ava[i][j]<<" "; } cout<<endl; } #endif for(i=1;i<=n;i++){ s[i]=false; y=0; for(j=1;j<=n;j++){ y+=ava[i][j]; } if(y==n) s[i]=true; y=0;/* for(j=1;j<=n;j++){ y+=ava[j][i]; } if(y==n) s[i]=true;*/ if(s[i]) x+=1; } cout<<x<<endl; }
标签:201709,cin,int,通信,网络,nownum,visited,ava,1001 来源: https://www.cnblogs.com/hyffff/p/14643319.html