Cutting edge (Bridge)
template
vector<pair<int, int> > ans;
vector<int> e[maxn];
void dfs(int u,int fa) {
dep[u] = dep[fa] + 1;
for(int v:e[u]) {
if(v==fa)
continue;
if(!dep[v]) {
dfs(v, u);
dp[u] += dp[v];
}
else {
if(dep[v]>dep[u]) {
dp[u]--;//down from u
}
else if(dep[v]<dep[u]) {
dp[u]++;//up form u
}
}
}
if(!dp[u]&&u!=1){
brige = 1;
}
}
\(dp[u]\)= (#of back-edges going up from u) − (# of back-edges going down from u) +\(\sum dp[v]\)
If a point does not back-edge, then indicating the presence of the bridge of FIG.
example
Bertown roads
CF118E
The meaning of problems
FIG n points to an m edges, undirected edges; To this now to FIG become edges having unidirectional FIG. M, and guaranteed to arrive one another between any two points
Thinking
DFS tree, and count the number of back-edge of each point, if it is 0 it represents the parent form cutting bridge, to the output 0
Links: https://xlorpaste.cn/28k1dx