1. 程式人生 > >nyoj-211-Cow Contest(floyd算法)

nyoj-211-Cow Contest(floyd算法)

http 沒有 strong 有關 size ron ems nyist class

題目鏈接

 1 /*
 2     Name:nyoj-211-Cow Contest
 3     Copyright:
 4     Author:
 5     Date: 2018/4/27 21:02:06
 6     Description:
 7     floyd算法
 8     大佬的驚奇思路 
 9 */
10 #include <iostream>
11 #include <cstdio>
12 #include <cstring>
13 using namespace std;
14 
15 const int MAXN = 105
; 16 const int INF = 0x3f3f3f3f; 17 int N, g[MAXN][MAXN], M; 18 19 void floyd() { 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 (g[i][k] && g[k][j]) 24 g[i][j] = 1;//有關系
25 } 26 } 27 } 28 } 29 int main() 30 { 31 while (cin>>N>>M, N+M) { 32 memset(g, 0, sizeof(g)); 33 for (int i=0; i<M; i++) { 34 int x, y; 35 cin>>x>>y; 36 g[x][y] = 1; 37 } 38
floyd(); 39 int i, j, ans=0; 40 for (i=1; i<=N; i++) { 41 for (j=1; j<=N; j++) { 42 if (i==j) continue; 43 if (g[i][j] == 0 && g[j][i] == 0) break;//和其他牛中的一頭沒有關系就不能確定排名 44 } 45 if (j > N) ans++; 46 } 47 cout<<ans<<endl; 48 } 49 return 0; 50 }

nyoj-211-Cow Contest(floyd算法)