Advertisement
Jasir

Articulation point

May 9th, 2018
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.92 KB | None | 0 0
  1. int dfs_num[mx], dfs_cnt, dfs_low[mx], dfs_parent[mx], n, vis[mx], root, child, art_ver[mx];
  2. vector <int> graph[mx];
  3.  
  4. void init(){
  5.     dfs_cnt = 1;
  6.     for(int j=1;j<=n;j++){
  7.         if(dfs_num[j]==0){
  8.             root = j; child = 0;
  9.             articulationpoint(j);
  10.             art_ver[j] = (child>1);
  11.         }
  12.     }
  13.     ans = 0;
  14.     for(int j=1;j<=n;j++){
  15.         if(art_ver[j]){
  16.             ans++;
  17.         }
  18.     }  
  19. }
  20.  
  21. void articulationpoint(int u){
  22.     dfs_low[u] = dfs_num[u] = dfs_cnt++;
  23.     for(int i=0;i<graph[u].size();i++){
  24.         if(dfs_num[graph[u][i]] == 0){
  25.             dfs_parent[graph[u][i]] = u;
  26.             if(u==root){
  27.                 child++;
  28.                 //cout << "root " << graph[u][i] <<" ";
  29.             }
  30.             articulationpoint(graph[u][i]);
  31.             if(dfs_low[graph[u][i]]>=dfs_num[u]){
  32.                 art_ver[u] = 1;
  33.             }
  34.             dfs_low[u] = min(dfs_low[u], dfs_low[graph[u][i]]);
  35.         }
  36.         else if(graph[u][i]!=dfs_parent[u]){
  37.             dfs_low[u] = min(dfs_low[u], dfs_num[graph[u][i]]);
  38.         }
  39.     }
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement