Poj-3660 Cow Contest
Link: www.bkjia.com
Use floyd to pass the closure to determine the outcome. In this way, all vertices a can reach are ranked after. All the points that can go to a are ranked before. For example, if the sum of "A", "ranking before" and "ranking after" is "n-1", the ranking is definite.
#include
#include
#include
#include
#include
using namespace std;const int MAX = 110;int n,m;int rank[MAX][MAX];int in[MAX] ,out[MAX];int ans;int main (){ int a,b; while (cin>>n>>m) { memset(rank,0,sizeof(rank)); memset(in,0,sizeof(in)); memset(out,0,sizeof(out)); ans = 0; while (m--) { cin>>a>>b; rank[a][b] = 1; } for(int k=1;k<=n;k++) for(int i=1;i<=n;i++) for(int j=1;j<=n;j++) { if (rank[i][k] == 1 && rank[k][j] == 1) rank[i][j] =1; } for(int i=1;i<=n;i++) { int res = 0; for(int j=1;j<=n;j++) res += rank[i][j] + rank[j][i]; if (res == n-1) ans++; } cout<