标签:style blog http color io os ar for sp
1 //Accepted 176 KB 16 ms 2 //一头牛,如果rank是能确定的,那么能打败他的牛的个数和被他打败的牛的个数的总和为n-1 3 #include <cstdio> 4 #include <cstring> 5 #include <iostream> 6 #include <queue> 7 #include <cmath> 8 #include <algorithm> 9 using namespace std; 10 /** 11 * This is a documentation comment block 12 * 如果有一天你坚持不下去了,就想想你为什么走到这儿! 13 * @authr songt 14 */ 15 const int imax_n = 105; 16 int map1[imax_n][imax_n]; 17 int n,m; 18 void floyd(int map[][imax_n]) 19 { 20 for (int k=1;k<=n;k++) 21 for (int i=1;i<=n;i++) 22 for (int j=1;j<=n;j++) 23 if (map[i][k]!=0 && map[k][j]!=0) 24 { 25 map[i][j]=1; 26 } 27 } 28 int main() 29 { 30 while (scanf("%d%d",&n,&m)!=EOF) 31 { 32 memset(map1,0,sizeof(map1)); 33 int x,y; 34 for (int i=0;i<m;i++) 35 { 36 scanf("%d%d",&x,&y); 37 map1[x][y]=1; 38 } 39 floyd(map1); 40 int ans=0; 41 for (int i=1;i<=n;i++) 42 { 43 int temp=0; 44 for (int j=1;j<=n;j++) 45 temp+=map1[i][j]+map1[j][i]; 46 if (temp==n-1) ans++; 47 } 48 printf("%d\n",ans); 49 } 50 return 0; 51 }
标签:style blog http color io os ar for sp
原文地址:http://www.cnblogs.com/djingjing/p/4032197.html