Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstdio>
- #include <cstring>
- #include <queue>
- #include <vector>
- using namespace std;
- #define si(a) scanf("%d",&a)
- #define f first
- #define s second
- #define mp(a,b) make_pair(a,b)
- #define MAX 1005
- int vis[MAX];
- vector<int> graph[MAX];
- void dfs(int now)
- {
- if(vis[now])
- return ;
- //cout<<now+1<<endl;
- vis[now]=1;
- for(int i=0;i<graph[now].size();i++)
- dfs(graph[now][i]);
- return ;
- }
- int main()
- {
- //freopen("input","r",stdin);
- int n,m,i;
- si(n);si(m);
- for(i=0;i<m;i++){
- int u,v;
- si(u);si(v);
- u--;v--;
- graph[u].push_back(v);
- graph[v].push_back(u);
- }
- dfs(0);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement