Submission #6390102


Source Code Expand

Copy
    #include<bits/stdc++.h>
     
    using namespace std;
     
    #define all(a) a.begin(),a.end()
    #define F first
    #define S second
    #define pb push_back
    #define ll long long
    #define vi vector<int>
    #define pi pair<int,int>
    #define mp make_pair
     
    #ifdef LOCAL
    #include "debug.h"
    #else
    #define debug(...) 42
    #endif
     
    const int mod=1e9+7;
     
    mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
    template<typename A,typename B> istream& operator>>(istream&,pair<A,B>&);
    template<typename A> istream& operator>>(istream&,vector<A>&);
    void add(int&,int);
    int mul(int,int);
    int powz(int,int);
    int sub(int,int);
    template<typename A> ostream& operator<<(ostream&,vector<A>&);
     
    const int N=500001;
    int fa[N];
    vi adj[N];
    int sz[N];
    int get(int x){
    	if(fa[x]==x)return x;
    	return fa[x]=get(fa[x]);
    }
     
    void merge(int x,int y){
    	x=get(x),y=get(y);
    	if(sz[y]>sz[x])swap(x,y);
    	sz[x]+=sz[y];
    	fa[y]=x;
    }
    vector<pi>ans;
    int cnt[N];
    void dfs(int u,int p){
    	for(auto i:adj[u]){
    		if(i!=p)
    		dfs(i,u);
    	}
    	if(cnt[u]&1){
    		if(p==-1)return;
    		ans.pb(mp(u,p));
    		cnt[u]++;
    	}
    	else{
    		if(p==-1)return;
    		ans.pb(mp(p,u));
    		cnt[p]++;
    	}
    }
    void solve(){
    	int n,m;
    	cin>>n>>m;
    	for(int i=0;i<n;i++)fa[i]=i,sz[i]=1;
    	
    	for(int i=0;i<m;i++){
    		int x,y;
    		cin>>x>>y;
    		x--;y--;
    		if(get(x)==get(y)){
    			ans.pb(mp(x,y));
    			cnt[x]++;
    		}
    		else{
    			merge(x,y);
    			adj[x].pb(y);
    			adj[y].pb(x);
    		}
     
    	}
    	if(m&1){
    		cout<<"-1";
    		return;
    	}
    	dfs(0,-1);
    	for(auto i:ans)cout<<i.F+1<<' '<<i.S+1<<"\n";
    }
     
    signed main(){
    	ios_base::sync_with_stdio(false);
    	cin.tie(0);
    	int tc=1;
    	//cin>>tc;
    	for(int _=0;_<tc;_++){
    		//cout<<"Case #"<<_+1<<": ";
    		solve();
    		if(_!=tc-1)
    		cout<<"\n";
    	}
    }
     
    int mul(int a,int b)
    {
    	return ((a)*1ll*(b))%mod;
    }
     
    void add(int &a,int b)
    {
    	a+=b;
    	if(a>=mod)a-=mod;
    }
     
    int sub(int a,int b){
    	a-=b;
    	if(a<0){
    		a+=mod;
    	}
    	return a;
    }
     
    int powz(int a,int b)
    {
    	int res=1;
    	while(b)
    	{
    		if(b&1)res=mul(res,a);
    		b/=2;
    		a=mul(a,a);
    	}
    	return res;
    }
     
    template <typename A, typename B>
    istream& operator>>(istream& input,pair<A,B>& x) {
    	input>>x.F>>x.S;
    	return input;
    }
     
    template <typename A>
    istream& operator>>(istream& input,vector<A>& x) {
    	for(auto& i:x)
    		input>>i;
    	return input;
    }
     
    template<typename A>
    ostream& operator<<(ostream& output,vector<A>& x) {
    	for(auto& i:x)
    	    output<<i<<' ';
    	return output;
    }

Submission Info

Submission Time
Task B - Even Degrees
User priyam2k
Language C++ (GCC 5.4.1)
Score 0
Code Size 3090 Byte
Status CE

Compile Error

./Main.cpp:22:5: error: ‘mt19937’ does not name a type
     mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
     ^
./Main.cpp: In function ‘void dfs(int, int)’:
./Main.cpp:49:15: error: ‘i’ does not name a type
      for(auto i:adj[u]){
               ^
./Main.cpp:53:6: error: expected ‘;’ before ‘if’
      if(cnt[u]&1){
      ^
./Main.cpp:53:6: error: expected primary-expression before ‘if’
./Main.cpp:53:6: error: expected ‘;’ before ‘if’
./Main.cpp:53:6: error: expected primary-expression before ‘if’
./Main.cpp:53:6: error: expected ‘)’ before ‘if’
./Main.cpp: In function ‘void solve()’:
./Main.cpp:89:15: error: ‘i’ does not name a type
      for(auto i:ans)cout<<i.F+1<<' '<<i.S+1<<"\n";
               ^
./Main.cpp:90:5: error: expected ‘;’ before ‘}’ token
     }
     ^
./Main.cpp:90:5: error: expected primary-expression before ‘}’ token
./Main.cpp:90:5: error: expected ‘;’ before ‘}’ token
./Main.cpp:90:5: error: expected primary-expression before ‘}’ token
./Main.cpp:90:5: error...