Submission #936029

#TimeUsernameProblemLanguageResultExecution timeMemory
936029RegulusNaboj (COCI22_naboj)C++17
0 / 110
177 ms40128 KiB
#include <bits/stdc++.h> #define IO ios::sync_with_stdio(false);cin.tie(0); #define debug(x) cerr << #x << " = " << (x) << ' ' #define bug(x) cerr << (x) << ' ' #define endl cerr << '\n' #define all(v) (v).begin(), (v).end() #define SZ(v) (ll)(v).size() #define lowbit(x) (x)&-(x) #define pb emplace_back #define F first #define S second using namespace std; using ll = long long; using pll = pair<ll, ll>; //#define TEST const int N = 2e5+5; bool del[N]; set<pll> g[N]; vector<pll> ans; priority_queue<pll, vector<pll>, greater<pll> > pq; inline void no() { cout << "-1\n"; exit(0); } int main(void) { IO int n, i, m; cin >> n >> m; if (m != n-1) assert(0); for (i=0; i < m; ++i) { int x, y; cin >> x >> y; g[x].insert({y, 1}), g[y].insert({y, 0}); } for (i=1; i <= n; ++i) pq.push({SZ(g[i]), i}); while (!pq.empty()) { int deg = pq.top().F, x = pq.top().S; pq.pop(); if (deg != 1) { if (!pq.empty()) no(); ans.pb(x, 0); break; } pll p = *g[x].begin(); int v = p.F, f = p.S; ans.pb(x, f); g[v].erase({x, f^1}); } cout << SZ(ans) << '\n'; for (auto p : ans) cout << p.F << ' ' << p.S << '\n'; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...