Saleh127

Light OJ 1063 / Articulation Point

Apr 12th, 2022
1,045
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.72 KB | None | 0 0
  1. /***
  2.  created: 2022-04-12-14.23.55
  3. ***/
  4.  
  5. #include <bits/stdc++.h>
  6. using namespace std;
  7. #define ll long long
  8. #define test int tt; cin>>tt; for(int cs=1;cs<=tt;cs++)
  9. #define get_lost_idiot return 0
  10. #define nl '\n'
  11.  
  12. ll a[200005];
  13. vector<ll>g[200005];
  14. bool v[200005];
  15. ll timer;
  16. ll low[200005],in[200005];
  17.  
  18.  
  19. void dfs(ll vertex,ll parent)
  20. {
  21.     v[vertex]=1;
  22.  
  23.     low[vertex] = in[vertex] = ++timer;
  24.  
  25.     ll edge=0;
  26.  
  27.     for(auto child:g[vertex])
  28.     {
  29.         if(child==parent) continue;
  30.  
  31.         if(v[child])
  32.         {
  33.             low[vertex]=min(low[vertex],in[child]);
  34.         }
  35.         else
  36.         {
  37.             dfs(child,vertex);
  38.  
  39.             if(low[child]>=in[vertex] && parent!=-1)
  40.             {
  41.                 a[vertex]=1;
  42.             }
  43.             low[vertex]=min(low[vertex],low[child]);
  44.  
  45.             edge++;
  46.         }
  47.     }
  48.  
  49.     if(parent==-1 && edge>1)
  50.     {
  51.         a[vertex]=1;
  52.     }
  53. }
  54.  
  55.  
  56. void clr(ll n)
  57. {
  58.     for(ll i=0; i<n+4; i++)
  59.     {
  60.         g[i].clear();
  61.         v[i]=0;
  62.         low[i]=-1;
  63.         in[i]=-1;
  64.         a[i]=0;
  65.     }
  66.  
  67.     timer=0;
  68. }
  69.  
  70. int main()
  71. {
  72.  
  73.     ios_base::sync_with_stdio(0);
  74.     cin.tie(0);
  75.     cout.tie(0);
  76.  
  77.     test
  78.     {
  79.         ll n,m,i,j,k,l;
  80.  
  81.         cin>>n>>m;
  82.  
  83.         clr(n+2);
  84.  
  85.         for(i=0; i<m; i++)
  86.         {
  87.             cin>>j>>k;
  88.             g[j].push_back(k);
  89.             g[k].push_back(j);
  90.  
  91.         }
  92.  
  93.         for(i=1; i<=n; i++)
  94.         {
  95.             if(v[i]==0)
  96.             {
  97.                 dfs(i,-1);
  98.             }
  99.         }
  100.  
  101.         l=0;
  102.  
  103.         for(i=1; i<=n; i++)
  104.         {
  105.             if(a[i]==1) l++;
  106.         }
  107.  
  108.         cout<<"Case "<<cs<<": "<<l<<nl;
  109.  
  110.     }
  111.  
  112.     get_lost_idiot;
  113.  
  114. }
  115.  
Advertisement
Add Comment
Please, Sign In to add comment