Skip to content

Instantly share code, notes, and snippets.

@WildfootW
Created August 9, 2015 03:04
Show Gist options
  • Save WildfootW/bca406b9839b2de5ed03 to your computer and use it in GitHub Desktop.
Save WildfootW/bca406b9839b2de5ed03 to your computer and use it in GitHub Desktop.
queue<int> q;
q.push (1);
while(! q.empty())
{
for(int j=0;j<q[i].size();j++)
{
if(!u[g[i][j]])
{
q.push(g[i][j]);
u[g[i][j]]=1;
}
}
}
void dfs (int i)
{
u[i]=true;
for(int j=0;j<g[i].size();j++)
{
if(!u[g[i][j])
dfs(g[i][j]);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment