http://acm.hdu.edu.cn/showproblem.php?pid=3357
View Code
1 //3357 2 #include <cstdio> 3 #include <cstring> 4 using namespace std; 5 6 const int N=250; 7 int g[N][N]; 8 int main() 9 { 10 int n,m,C=0; 11 while(scanf("%d%d",&n,&m),n||m) 12 { 13 memset(g,0,sizeof(g)); 14 for(int i=1;i<=n;i++) g[i][i]=1; 15 int cnt=0; 16 while(m--) 17 { 18 int u,v; 19 scanf("%d%d",&u,&v); 20 if(g[v][u]) 21 { 22 cnt++; 23 continue; 24 } 25 if(g[u][v]) continue; 26 g[u][v]=1; 27 for(int i=1;i<=n;i++) if(g[i][u]) 28 for(int j=1;j<=n;j++) if(g[v][j]) g[i][j]=1; 29 } 30 printf("%d. %d\n",++C,cnt); 31 } 32 return 0; 33 }