Submission #6390108


Source Code Expand

Copy
    #pragma GCC optimize("Ofast")
    #pragma GCC optimize("no-stack-protector")
    #pragma GCC optimize("unroll-loops")
    #pragma GCC optimize("fast-math")
    #pragma GCC target("sse,sse2,sse3,ssse3,popcnt,abm,mmx,tune=native")
    #include <iostream>
    #include <vector>
    #include <algorithm>
    #include <set>
    #include <map>
    #include <unordered_set>
    #include <unordered_map>
    #include <stdio.h>
    #include <cstdio>
    #include <math.h>
    #include <cmath>
    #include <string>
    #include <cstring>
    #include <queue>
    #include <deque>
    #include <random>
    #include <iomanip>
    #include <bitset>
                            
    using namespace std;
                            
    template<typename T> void uin(T &a, T b) {
        if (b < a) {
            a = b;
        }
    }
                            
    template<typename T> void uax(T &a, T b) {
        if (b > a) {
            a = b;
        }
    }
     
     
    #define int long long
    #define ghost signed
    #define left left228
    #define right right228
    #define prev prev228
    #define list list228
     
    const int N = 100 * 1000 + 228;
     
    namespace DSU
    {
    	int p[N], sz[N];
     
    	void init(int n) {
    		for (int i = 1; i <= n; ++i) {
    			p[i] = i;
    			sz[i] = 1;
    		}
    	}
     
    	int getp(int v) {
    		if (v == p[v]) return v;
    		p[v] = getp(p[v]);
    		return p[v];
    	}
     
    	bool join(int u, int v) {
    		u = getp(u);
    		v = getp(v);
    		if (u == v) return 0;
    		if (sz[u] < sz[v]) {
    			p[u] = v;
    			sz[v] += sz[u];
    		} else {
    			p[v] = u;
    			sz[u] += sz[v];
    		}
    		return 1;
    	}
    };
     
    vector<int> g[N];
    vector< pair<int, int> > ans;
    int deg[N];
     
    void dfs(int v, int par = -1) {
    	for (int to : g[v]) {
    		if (to != par) dfs(to, v);
    	}
    	if (deg[v]) {
    		ans.emplace_back(v, par);
    	} else {
    		if (par != -1) {
    			ans.emplace_back(par, v);
    			deg[par] ^= 1;
    		}
    	}
    }
     
    int a[100];
     
    ghost main() {
        ios_base::sync_with_stdio(false);
        cin.tie(0);
    	int n, m;
    	cin >> n >> m;
    	if (m & 1) {
    		cout << -1 << '\n';
    		return 0;
    	}
    	DSU::init(n);
    	for (int i = 0; i < m; ++i) {
    		int u, v;
    		cin >> u >> v;
    		if (DSU::join(u, v)) {
    			g[u].push_back(v);
    			g[v].push_back(u);
    		} else {
    			ans.emplace_back(u, v);
    			deg[u] ^= 1;
    		}
    	}
    	dfs(1);
    	for (auto p : ans) cout << p.first << ' ' << p.second << '\n';
        return 0;
    } // kek ;

Submission Info

Submission Time
Task B - Even Degrees
User priyam2k
Language C++14 (GCC 5.4.1)
Score 700
Code Size 2762 Byte
Status AC
Exec Time 63 ms
Memory 14960 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 700 / 700
Status
AC × 2
AC × 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 AC 63 ms 11504 KB
02.txt AC 63 ms 11504 KB
03.txt AC 63 ms 11504 KB
04.txt AC 63 ms 11504 KB
05.txt AC 3 ms 3584 KB
06.txt AC 49 ms 8688 KB
07.txt AC 49 ms 8688 KB
08.txt AC 49 ms 8688 KB
09.txt AC 49 ms 8688 KB
10.txt AC 3 ms 3584 KB
11.txt AC 36 ms 6588 KB
12.txt AC 36 ms 6584 KB
13.txt AC 36 ms 6584 KB
14.txt AC 36 ms 6588 KB
15.txt AC 3 ms 3584 KB
16.txt AC 35 ms 6148 KB
17.txt AC 35 ms 6272 KB
18.txt AC 35 ms 6272 KB
19.txt AC 35 ms 6276 KB
20.txt AC 3 ms 3584 KB
21.txt AC 32 ms 6008 KB
22.txt AC 32 ms 6008 KB
23.txt AC 32 ms 6008 KB
24.txt AC 32 ms 6008 KB
25.txt AC 3 ms 3584 KB
26.txt AC 3 ms 3584 KB
27.txt AC 3 ms 3584 KB
28.txt AC 56 ms 14064 KB
29.txt AC 56 ms 14960 KB
30.txt AC 3 ms 3584 KB
31.txt AC 3 ms 3584 KB
32.txt AC 3 ms 3584 KB
33.txt AC 3 ms 3584 KB
34.txt AC 3 ms 3584 KB
s1.txt AC 3 ms 3584 KB
s2.txt AC 3 ms 3584 KB