Created
November 10, 2015 11:29
-
-
Save koosaga/77796a114069c8cd88ce to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int low[2505], dfn[2505], par[2505], piv; | |
int cpiv, vis[2505], pcc[2505]; | |
vector<int> bcc[2505]; | |
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]){ | |
pcc[w] = ++cpiv; | |
bcc[x].push_back(cpiv); | |
color(w, cpiv); | |
} | |
else{ | |
pcc[w] = c; | |
color(w, c); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment