#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;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
10 ms |
19548 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
177 ms |
40128 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
10 ms |
19548 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |