标签:
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1410 Accepted Submission(s): 436
#include<iostream> #include<cstdio> #include<cstring> #include<string> #include<cmath> #include<algorithm> #include<cstdlib> #include<queue> #include<vector> #include<stack> using namespace std; int n,m; bool mp[300][300]; void update(int x,int y) { mp[x][y]=true; for(int i=1;i<=n;i++) { if(mp[i][x]) mp[i][y]=true; } for(int i=1;i<=n;i++) { if(mp[y][i]) { mp[x][i]=true; for(int j=1;j<=n;j++) { if(mp[j][y]) mp[j][i]=true; } } } } int main() { int x,y,cnt=0; while(scanf("%d%d",&n,&m)!=EOF) { if(n==0&&m==0) break; int ans=0; memset(mp,0,sizeof(mp)); for(int i=0;i<m;i++) { scanf("%d%d",&x,&y); if(x==y) ans++; else if(mp[y][x]) ans++; else if(!mp[x][y]) { update(x,y); } } printf("%d. %d\n",++cnt,ans); } return 0; }
标签:
原文地址:http://www.cnblogs.com/a972290869/p/4423063.html