Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- vector<int>adj[100];
- bool visited[100];
- void dfs(int src)
- {
- visited[src]=true;
- cout<<src<<" ";
- for(int i=0;i<adj[src][i];i++)
- {
- int child=adj[src][i];
- if(visited[child]==0)
- {
- dfs(child);
- }
- }
- }
- int main()
- {
- int node,edge,m,n;
- cin>>node>>edge;
- while(edge--)
- {
- cin>>m>>n;
- adj[m].push_back(n);
- adj[n].push_back(m);
- }
- dfs(1);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement