POJ3275 Ranking the Cows
#include <iostream>
#include <cstdio>
#include <bitset>
using namespace std;
const int maxn = ;
int n, m;
bitset<maxn> maps[maxn];
void floyd() {
for (int k = ; k <= n; k++) {
for (int i = ; i <= n; i++) {
if (maps[i][k]) maps[i] |= maps[k];
}
}
}
int main() {
scanf("%d%d",&n,&m);
for (int i = ; i <= m; i++) {
int u, v; scanf("%d%d",&u,&v);
maps[u][v] = true;
}
floyd();
int ans = ;
for (int i = ; i <= n; i++) {
for (int j = i+; j <= n; j++) {
if (!maps[i][j] && !maps[j][i]) ans++;
}
}
printf("%d\n",ans);
return ;
}