Skip to content

Instantly share code, notes, and snippets.

@CsengerG
Created December 23, 2015 11:19
Show Gist options
  • Select an option

  • Save CsengerG/231b9d4e5b48ed36d1e3 to your computer and use it in GitHub Desktop.

Select an option

Save CsengerG/231b9d4e5b48ed36d1e3 to your computer and use it in GitHub Desktop.
Depth-first search
#include <bits/stdc++.h>
using namespace std;
const int maxn=100000;
vector<int> g[maxn];
bool explored[maxn];
void dfs(int v){
explored[v]=true;
for(int i=0;i<g[v].size();++i){
int neighbor=g[v][i];
if(explored[neighbor]==false) dfs(neighbor);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment