Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // depth should be cleared with 0 everytest
- // timer should be cleared
- #include<bits/stdc++.h>
- using namespace std;
- const int MX= (1<<20);
- vector < int > v[MX];
- int timer , low[MX] , depth[MX];
- vector < int > cutpoints;
- vector < pair < int , int > > bridges;
- void dfs(int x , int p){
- int cc = 0 , is = 0;
- depth[x] = low[x] = ++timer;
- int l=v[x].size();
- for(int j=0;j<l;j++){
- int nxt=v[x][j];
- if(nxt == p) continue;
- if(depth[nxt] == 0) {
- ++cc;
- dfs(nxt , x);
- low[x] = min(low[x] , low[nxt]);
- if(low[nxt] > depth[x]) bridges.push_back({x , nxt});
- if(low[nxt] >= depth[x] && p!=-1) is = 1;
- }
- else low[x] = min(low[x] , depth[nxt]);
- }
- if(p == -1 && cc>1) is = 1;
- if(is) cutpoints.push_back(x);
- }
- int main(){
- int n;
- cutpoints.clear();
- bridges.clear();
- timer = 0;
- for(int j=1;j<=n;j++){
- v[j].clear();
- depth[j] = 0;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement