题意:牛有等级,a,b表示a>b 问有几头牛可以确定等级
floyd跑一边。。。。。看左右加起来是否为n - 1
链接:poj 3660
#include<iostream>
#include<algorithm>
#include<map>
#include<string>
#include<vector>
#include<set>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<stack>
#include<queue>
#define maxn 1505
#define INF 0x3f3f3f3f
using namespace std;
int mapp[maxn][maxn];
int n, m;
void floyd() {
for(int k = 1; k <= n; k++) {
for(int i = 1; i <= n; i++) {
for(int j = 1; j <= n; j++) {
if(mapp[i][k] && mapp[k][j]) {
mapp[i][j] = 1;
}
}
}
}
}
int main()
{
while(~scanf("%d %d", &n, &m)) {
memset(mapp, 0, sizeof(mapp));
int a, b;
while(m--) {
scanf("%d %d", &a, &b);
mapp[a][b] = 1;
}
floyd();
int ans = 0;
for(int i = 1; i <= n; i++) {
int res = 0;
for(int j = 1; j <= n; j++) {
if(mapp[j][i] || mapp[i][j] && i != j)
res++;
}
if(res == n - 1)
ans++;
}
printf("%d\n", ans);
}
return 0;
}