Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- #define pb(a) push_back(a)
- #define mp(a,g) make_pair(a,g)
- const int MAX = 10005;
- int par[MAX] = {0},child[MAX]={0},low[MAX] = {0},tym[MAX]={0};
- bool visit[MAX]={0},isCut={0};
- static int t=0;
- stack <pair <int,int> > bc;
- vector <int> a[MAX];
- int odd=0,even=0;
- void BCdfs(int s){
- visit[s] = true;
- low[s]=tym[s]=t++;
- for(int i=0;i<a[s].size();i++){
- int v = a[s][i];
- if(!visit[v]){
- par[v] = s;
- child[s]++;
- bc.push(mp(s,v));
- BCdfs(v);
- low[s] = min(low[s],low[v]);
- if((tym[s]==1 and child[s]>1)||( low[v]>=tym[s])){
- set<int> nodes;
- while(bc.top().first !=s || bc.top().second !=v){
- nodes.insert(bc.top().first);
- nodes.insert(bc.top().second);
- bc.pop();
- }
- nodes.insert(bc.top().first);
- nodes.insert(bc.top().second);
- bc.pop();
- if(nodes.size()!=0 and nodes.size()&1)odd++;
- else even++;
- }
- }
- else if(v!=par[s] && tym[v]<low[s]){
- low[s] = min(low[s],tym[v]);
- bc.push(mp(s,v));
- }
- }
- }
- int main(){
- int n,m,x,y;cin>>n>>m;
- while(m--){
- cin>>x>>y;
- a[x+1].pb(y+1);
- a[y+1].pb(x+1);
- }
- par[1] = -1;
- for(int i=1;i<=n;i++){
- if(!visit[i])
- BCdfs(i);
- }
- set <int> nodes;
- while(!bc.empty()){
- cout<<bc.top().first<<" "<<bc.top().second<<"\n";
- nodes.insert(bc.top().first);
- nodes.insert(bc.top().second);
- bc.pop();
- }
- if(nodes.size()!=0 and nodes.size()&1)odd++;
- else if(nodes.size()!=0 ) even++;
- cout<<odd<<" "<<even;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement