답안 #936033

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
936033 2024-03-01T03:04:37 Z Regulus Naboj (COCI22_naboj) C++17
25 / 110
331 ms 48824 KB
#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;
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({x, 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 != SZ(g[x]))
        {
            if (deg == 1) ans.pb(x, 0);
            continue;
        }

        pll p = *g[x].begin();
        int v = p.F, f = p.S;
        ans.pb(x, f);

        g[v].erase({x, f^1});
        if (!g[v].empty()) pq.push({SZ(g[v]), v});
    }

    if (SZ(ans) != n) assert(0);
    cout << SZ(ans) << '\n';
    reverse(all(ans));
    for (auto p : ans) cout << p.F << ' ' << p.S << '\n';

    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Runtime error 10 ms 19508 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 320 ms 46312 KB Output is correct
2 Correct 298 ms 47616 KB Output is correct
3 Correct 119 ms 28836 KB Output is correct
4 Correct 281 ms 48052 KB Output is correct
5 Correct 300 ms 46776 KB Output is correct
6 Correct 277 ms 48568 KB Output is correct
7 Correct 308 ms 48824 KB Output is correct
8 Correct 213 ms 40124 KB Output is correct
9 Correct 331 ms 48312 KB Output is correct
10 Correct 275 ms 47544 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Runtime error 10 ms 19508 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -