Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- #define pb push_back
- #define ll long long
- #define pii pair<int,int>
- #define pll pair<ll,ll>
- #define M 100007
- #define INF 1e9
- #define INFL 1e18
- #define PI acos(-1)
- #define mp make_pair
- #define fast_in_out ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
- vector<int>adj[M];
- int parent[M];
- int low[M];
- int d[M];
- int visited[M];
- bool isArticulationPoint[M];
- int Time=0;
- bool mark[M];
- vector<pair<int,int> >ans;
- void DFS(int u,int root)
- {
- Time=Time+1;
- visited[u]=1;
- d[u]=low[u]=Time;
- int noOfChildren=0;
- for(int i=0;i<adj[u].size();i++)
- {
- int v=adj[u][i];
- if(v==parent[u])
- continue;
- if(visited[v])
- {
- low[u]=min(low[u],d[v]);
- }
- else
- {
- parent[u]=v;
- DFS(v,root);
- low[u]=min(low[u],low[v]);
- if(low[v]>=d[u] && u!=root)
- {
- isArticulationPoint[u]=true;
- ans.pb(mp(u,v));
- }
- noOfChildren=noOfChildren+1;
- }
- if(u==root && noOfChildren>1)
- {
- isArticulationPoint[u]=true;
- ans.pb(mp(u,adj[u][0]));
- }
- }
- }
- int main()
- {
- int n;
- cin>>n;
- for(int i=0;i<n;i++)
- {
- int x,y;
- cin>>x>>y;
- adj[x].pb(y);
- adj[y].pb(x);
- }
- DFS(1,1);
- for(int i=1;i<=n;i++)
- {
- if(isArticulationPoint[i])
- cout<<i<<endl;
- //cout<<ans[i].first<<" "<<ans[i].second<<endl;
- }
- return 0;
- }
- //7
- //1 2
- //1 3
- //3 4
- //3 7
- //4 5
- //4 6
- //6 7
- //
Advertisement
Add Comment
Please, Sign In to add comment