标签:
3 2
1 2
1 3
1
#include<iostream> #include<cstdio> #include<string> #include<cstring> #include<algorithm> #include<vector> using namespace std; const int maxn = 105; const int maxint = 100000000; int n,m,g[maxn][maxn],tg[maxn][maxn],ans,nowans; void input(){ cin>>n>>m; int u,v; for(int i = 1;i <= m;i++){ cin>>u>>v; g[u][v] = 1; } } void build(){ for(int k = 1;k <= n;k++){ for(int i = 1;i <= n;i++){ for(int j = 1;j <= n;j++){ if(k != i && k != j && i != j) g[i][j] = g[i][j] || (g[i][k] && g[k][j]); } } } for(int i = 1;i <= n;i++){ nowans = 0; for(int j = 1;j <= n;j++){ if(g[i][j]) nowans++; if(g[j][i]) nowans++; } if(nowans == n-1) ans++; } cout<<ans<<endl; } int main(){ input(); build(); }
标签:
原文地址:http://www.cnblogs.com/hyfer/p/5812608.html