标签:
Tyvj 2059 元芳看电影
3 2
1 2
1 3
1
1 #include<iostream> 2 #include<cstdio> 3 #include<string> 4 #include<cstring> 5 #include<algorithm> 6 #include<vector> 7 using namespace std; 8 const int maxn = 105; 9 const int maxint = 100000000; 10 int n,m,g[maxn][maxn],tg[maxn][maxn],ans,nowans; 11 void input(){ 12 cin>>n>>m; 13 int u,v; 14 for(int i = 1;i <= m;i++){ 15 cin>>u>>v; 16 g[u][v] = 1; 17 } 18 } 19 void build(){ 20 for(int k = 1;k <= n;k++){ 21 for(int i = 1;i <= n;i++){ 22 for(int j = 1;j <= n;j++){ 23 if(k != i && k != j && i != j) g[i][j] = g[i][j] || (g[i][k] && g[k][j]); 24 } 25 } 26 } 27 for(int i = 1;i <= n;i++){ 28 nowans = 0; 29 for(int j = 1;j <= n;j++){ 30 if(g[i][j]) nowans++; 31 if(g[j][i]) nowans++; 32 } 33 if(nowans == n-1) ans++; 34 } 35 cout<<ans<<endl; 36 } 37 int main(){ 38 input(); 39 build(); 40 }
标签:
原文地址:http://www.cnblogs.com/hyfer/p/4835169.html