Submission #6390098


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 PyPy2 (5.6.0)
Score 0
Code Size 3090 Byte
Status RE
Exec Time 34 ms
Memory 28396 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 0 / 700
Status
RE × 2
RE × 36
Set Name Test Cases
Sample s1.txt, s2.txt
All 01.txt, 02.txt, 03.txt, 04.txt, 05.txt, 06.txt, 07.txt, 08.txt, 09.txt, 10.txt, 11.txt, 12.txt, 13.txt, 14.txt, 15.txt, 16.txt, 17.txt, 18.txt, 19.txt, 20.txt, 21.txt, 22.txt, 23.txt, 24.txt, 25.txt, 26.txt, 27.txt, 28.txt, 29.txt, 30.txt, 31.txt, 32.txt, 33.txt, 34.txt, s1.txt, s2.txt
Case Name Status Exec Time Memory
01.txt RE 34 ms 27628 KB
02.txt RE 34 ms 27884 KB
03.txt RE 34 ms 27372 KB
04.txt RE 34 ms 26732 KB
05.txt RE 34 ms 27116 KB
06.txt RE 34 ms 28396 KB
07.txt RE 34 ms 26732 KB
08.txt RE 34 ms 27884 KB
09.txt RE 34 ms 27244 KB
10.txt RE 34 ms 28012 KB
11.txt RE 34 ms 27628 KB
12.txt RE 34 ms 27628 KB
13.txt RE 34 ms 27372 KB
14.txt RE 34 ms 27244 KB
15.txt RE 34 ms 26988 KB
16.txt RE 34 ms 26348 KB
17.txt RE 33 ms 26476 KB
18.txt RE 34 ms 27884 KB
19.txt RE 34 ms 27372 KB
20.txt RE 33 ms 26348 KB
21.txt RE 34 ms 27884 KB
22.txt RE 33 ms 26476 KB
23.txt RE 34 ms 27756 KB
24.txt RE 33 ms 26604 KB
25.txt RE 33 ms 26348 KB
26.txt RE 34 ms 27244 KB
27.txt RE 34 ms 26988 KB
28.txt RE 33 ms 26604 KB
29.txt RE 33 ms 26604 KB
30.txt RE 34 ms 28012 KB
31.txt RE 34 ms 26604 KB
32.txt RE 34 ms 28012 KB
33.txt RE 34 ms 26988 KB
34.txt RE 34 ms 26732 KB
s1.txt RE 34 ms 27756 KB
s2.txt RE 33 ms 26476 KB