#include<bits/stdc++.h> using namespace std; const int N = 1e3+5; vector<int> graph[N]; bool visited[N]; void dfs(int vertex) { visited[vertex]=true; for(int child:graph[vertex]) { if(visited[child]) continue; dfs(child); } } int main() { int v,e,j,k; cin>>v>>e; for(int i=0;i<v;++i) { cin>>j>>k; graph[k].push_back(j); graph[j].push_back(k); } }
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter