Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- using namespace std;
- char color[100001];
- int pre[100001];
- int low[100001];
- int d[100001];
- int t=0;
- map<int,bool>points;
- map<pair<int,int>,bool>jerin;
- void dfs_visit(list<int>*adj,int source)
- {
- d[source]=++t;
- low[source]=d[source];
- color[source]='g';
- for(list<int>::iterator it=adj[source].begin();it!=adj[source].end();++it)
- {
- if(color[*it]=='w')
- {
- pre[*it]=source;
- dfs_visit(adj,*it);
- if(low[*it]>=d[source])
- {
- points[source]=1;
- }
- if(low[*it]>d[source])
- {
- if(*it>source){
- if(jerin[make_pair(source,*it)]==0)
- {
- jerin[make_pair(source,*it)]=1;
- }
- }
- else
- if(jerin[make_pair(*it,source)]==0)
- {
- jerin[make_pair(*it,source)]=1;
- }
- }
- if(low[*it]<low[source])
- {
- low[source]=low[*it];
- }
- }
- else if(color[*it]=='g' && pre[source]!=*it)
- {
- if(d[*it]<low[source])
- {
- low[source]=d[*it];
- }
- }
- }
- color[source]='b';
- }
- void dfs(list<int>*adj,int node)
- {
- for(int i=0;i<=node;i++)
- {
- pre[i]=-1;
- color[i]='w';
- low[i]=-1;
- d[i]=0;
- }
- for(int i=0;i<=node;i++)
- {
- if(color[i]=='w')
- {
- dfs_visit(adj,i);
- }
- }
- }
- int main()
- {
- // int case1;
- // cin>>case1;
- // for(int ii=1;ii<=case1;ii++)
- // {
- int node,edge;
- cout<<"input node numbers : ";
- cin>>node;
- cout<<"input edge numbers : ";
- cin>>edge;
- list<int>adj[node+1];
- t=0;
- map<pair<int,int>,bool>vis;
- for(int i=1;i<=edge;i++)
- {
- cout<<"edge "<<i<<" : ";
- int u,y,k,z=1,e=0;
- scanf("%d %d", &u, &k);
- adj[u].push_back(k);
- adj[k].push_back(u);
- }
- // for(int yy=1;yy<=k;yy++)
- // {
- // int r,rr;
- // scanf("%d",&rr);
- // int x=u;
- // int y=rr;
- // if(u>rr){
- // x=rr;
- // y=u;
- // }
- // if(vis[make_pair(x,y)]==0)
- // {
- // adj[x].push_back(y);
- // adj[y].push_back(x);
- // vis[make_pair(x,y)]=1;
- // }
- // }
- dfs(adj,node);
- map<pair<int,int>,bool>::iterator rit,rit1;
- rit=jerin.begin();
- rit1=rit;
- //printf("Case %d:",ii);
- cout<<endl<<jerin.size()<<" articulation bridze\n";
- for(rit1=jerin.begin();rit1!=jerin.end();++rit1)
- {
- cout<<rit1->first.first<<" - "<<rit1->first.second<<endl;;
- }
- jerin=std::map<pair<int,int>,bool>();
- //vis=std::map<pair<int,int>,bool>();
- //}
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement