上进小青年

导航

图论Hrbust1708许可证

http://acm.hrbust.edu.cn/index.php?m=ProblemSet&a=showProblem&problem_id=1708

 1 #include<stdio.h>
 2 #include<algorithm>
 3 #include<iostream>
 4 #include<string.h>
 5 using namespace std;
 6 const int maxn=110;
 7 int vis[maxn],ma[maxn][maxn],ans,u,v,n,m;;
 8 void dfs(int x)
 9 {
10     vis[x]=++ans;
11     for(int i=1;i<=n;i++){
12         if(!vis[i]&&ma[x][i])dfs(i);
13     }
14 }
15 int main()
16 {
17 
18     while(cin>>n>>m){
19 
20         ans=0;
21         memset(vis,0,sizeof(vis));
22         memset(ma,0,sizeof(ma));
23         for(int i=0;i<m;i++){
24             cin>>u>>v;
25             ma[u][v]=1;
26         }
27         dfs(1);
28         cout<<ans<<endl;
29     }
30 }
View Code

 

posted on 2016-08-10 21:31  上进小青年  阅读(157)  评论(0编辑  收藏  举报