POJ-3660-Cow Contest (floyd evaluate the passed closure)
Cow Contest
Thought: floyd calculates the transfer closure, which is used to determine whether each vertex can reach another vertex. Then, based on the number of points that can be reached and the sum of the number of times that can be reached is equal to n-1, to determine whether the point has been ranked
AC code:
#include#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include #define LL long long#define INF 0x7fffffffusing namespace std;int mp[105][105];int n, m;int main() { while(scanf(%d %d, &n, &m) != EOF) { int u, v; memset(mp, 0, sizeof(mp)); for(int i = 0; i < m; i ++) { scanf(%d %d, &u, &v); mp[u][v] = 1; } for(int k = 1; k <= n; k ++) { for(int i = 1; i <= n; i ++) { for(int j = 1; j <= n; j ++) { mp[i][j] = (mp[i][j] | (mp[i][k] & mp[k][j]) ); } } } for(int i = 1; i <= n; i ++) mp[i][i] = 0; int ans = 0; for(int i = 1; i <= n; i ++) { int cnt = 0; for(int j = 1; j <= n; j ++) { cnt += mp[i][j]; cnt += mp[j][i]; } if(cnt == n-1) ans ++; }www.bkjia.com printf(%d, ans); } return 0;}