POJ 3660 & NYOJ 211 Cow Contest (Floyd transfer closure), poj3660
Link: click here
There is an nheaded ox, and each ox has a unique and different level of competence. then, the two of them will play M games and give you the results of the M games. the question is, how many of you can determine your ranking? If a WINS B and B wins c, a wins c. and if you already know a wins the number of cattle + than a powerful number of cattle = N-1, then a ranking can certainly be launched.
Idea: Indicates data tangle ~~, After suddenly understanding it, I thought that the number of defeated instances and the number of defeated instances exactly equal to n-1 can be determined. Otherwise, they cannot be determined.
Code:
# Include <stdio. h> // (passing the closure floyed algorithm) # include <string. h >#include <iostream >#include <algorithm> using namespace std; const int maxn = 110; int map [maxn] [maxn]; int n, m; int main () {int I, j, k, x, y, cnt1, cnt2; while (~ Scanf ("% d", & n, & m), n + m) {memset (map, 0, sizeof (map); while (m --) {scanf ("% d", & x, & y); map [x] [y] = 1 ;}for (k = 1; k <= n; k ++) {for (I = 1; I <= n; I ++) {for (j = 1; j <= n; j ++) {if (map [I] [k] & map [k] [j]) {// printf ("$ % d $", I, k, k, j); map [I] [j] = 1; // assigned link }}} int count = 0; for (I = 1; I <= n; I ++) {cnt1 = 0; cnt2 = 0; for (j = 1; j <= n; j ++) {// if (I = j) continue; // if (map [I] [j] = 0 & map [j] [I] = 0) break; if (map [I] [j]) {// printf ("# I = % d j = % d #", I, j); cnt1 ++ ;} if (map [j] [I]) {// printf ("# j = % d I = % d #", j, I); cnt2 ++ ;}} if (cnt1 + cnt2 = (n-1) // The number of defeated instances plus the number of defeated instances exactly equal to n-1 {count ++ ;}} printf ("% d \ n", count);} return 0 ;}