Skip to content

Instantly share code, notes, and snippets.

@koosaga
Created November 10, 2015 14:20
Show Gist options
  • Save koosaga/6f6fd50dd7067901f1b1 to your computer and use it in GitHub Desktop.
Save koosaga/6f6fd50dd7067901f1b1 to your computer and use it in GitHub Desktop.
void dfs(int x, int p){
dfn[x] = low[x] = ++piv;
par[x] = p;
for(int i=0; i<graph[x].size(); i++){
int w = graph[x][i];
if(w == p) continue;
if(!dfn[w]){
dfs(w, x);
low[x] = min(low[x], low[w]);
}
else{
low[x] = min(low[x], dfn[w]);
}
}
}
void color(int x, int c){
if(c > 0) bcc[x].push_back(c);
vis[x] = 1;
for(int i=0; i<graph[x].size(); i++){
int w = graph[x][i];
if(vis[w]) continue;
if(dfn[x] <= low[w]){
bcc[x].push_back(++cpiv);
color(w, cpiv);
}
else{
color(w, c);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment