N (1 ≤ N ≤ 100) cows, conveniently numbered 1.. N , are participating in a programming contest. As we all know, some cows code better than others. Each cow has a certain constant skill rating that is unique among the competitors .
给几对牛AB,A比B强,求最多确定几头牛的排名。
当给出这样的关系时,排名被确定的牛至少有一头,这个很容易想出。
当图中某头牛与所有牛都能有关系时,他的排名也就被确定了(因为他与排名被确定的牛的关系确定了,可推到出自己排名)
用Floyd算法
无脑贴模板…….
#include<iostream>
#include<queue>
#include<math.h>
#include<stdio.h>
#include<string>
using namespace std;
#define N 100+5
#define LL long long int
#define pow(a) ((a)*(a))
#define INF 0x3f3f3f3f
#define mem(arr,a) memset(arr,a,sizeof(arr))
int n, m;
int cost[N][N];
bool judge(int x){
for (int i = 1; i <= n; i++){
if (cost[i][x] != INF || cost[x][i] != INF)continue;
return 0;
}
return 1;
}
int main(){
cin >> n >> m;
mem(cost, INF);
for (int i = 0; i < m; i++){
int a, b;
cin >> a >> b;
cost[a][b] = 1;
}
for (int i = 1; i <= n; i++)cost[i][i] = 0;
for (int i = 1; i <= n; i++){
for (int j = 1; j <= n; j++){
for (int k = 1; k <= n; k++){
cost[j][k] = min(cost[j][k], cost[j][i] + cost[i][k]);
}
}
}
cost;
int MAX = 0;
for (int i = 1; i <= n; i++){
if (judge(i))MAX++;
}
cout<<MAX<<endl;
}