POJ - 3660 Cow Contest(Floyd传递闭包)
#include<iostream>
using namespace std;
const int N = 110;
int w[N][N];
int main()
{
int n,m;cin>>n>>m;while(m--){
int a,b;cin>>a>>b;w[a][b]=1;}for(int k=1;k<=n;k++)for(int i=1;i<=n;i++)for(int j=1;j<=n;j++)w[i][j]|=(w[i][k]&&w[k][j]);int res=0;for(int i=1;i<=n;i++){
int cnt=0;for(int j=1;j<=n;j++)if(w[i][j]||w[j][i])cnt++;if(cnt==n-1) res++;}cout<<res<<endl;return 0;
}