답안 #781666

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
781666 2023-07-13T09:30:52 Z kebine Naboj (COCI22_naboj) C++17
110 / 110
155 ms 13924 KB
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define ld long double
#define fi first
#define se second

queue<int> q;
vector<int> child[200005], ans;
int par[200005];

int main() { 
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    /*
    1 2
    2 3
    3 4
    urutan penarikan = 4 -> 3 -> 2 -> 1
    urutan pengeboman = 1 -> 2 -> 3 -> 4
    3 3
    1 2
    2 3
    1 3
    3 -> 2 -> 1
    3 -> 1
    */
    int n, m;
    cin >> n >> m;
    for (int i = 0; i < m; i++) {
        int u, v;
        cin >> u >> v;
        child[u].push_back(v);
        par[v]++;
    }
    for (int i = 1; i <= n; i++) if (par[i] == 0) q.push(i);
    while (!q.empty()) {
        int x = q.front();
        q.pop();
        ans.push_back(x);
        for (auto u : child[x]) {
            par[u]--;
            if (par[u] == 0) q.push(u);
        }
    }
    for (int i = 1; i <= n; i++) {
        if (par[i] != 0) {
            cout << -1 << "\n";
            return 0;
        }
    }
    cout << (int)ans.size() << "\n";
    for (auto x : ans) cout << x << " 0" << "\n";
} 
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4948 KB Output is correct
2 Correct 2 ms 4948 KB Output is correct
3 Correct 2 ms 4948 KB Output is correct
4 Correct 2 ms 4960 KB Output is correct
5 Correct 2 ms 4948 KB Output is correct
6 Correct 2 ms 4948 KB Output is correct
7 Correct 2 ms 4948 KB Output is correct
8 Correct 2 ms 4948 KB Output is correct
9 Correct 2 ms 4948 KB Output is correct
10 Correct 2 ms 4948 KB Output is correct
11 Correct 2 ms 4948 KB Output is correct
12 Correct 2 ms 4948 KB Output is correct
13 Correct 2 ms 4948 KB Output is correct
14 Correct 2 ms 5012 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 75 ms 12772 KB Output is correct
2 Correct 67 ms 12868 KB Output is correct
3 Correct 31 ms 9112 KB Output is correct
4 Correct 75 ms 12836 KB Output is correct
5 Correct 69 ms 12792 KB Output is correct
6 Correct 69 ms 12772 KB Output is correct
7 Correct 91 ms 12868 KB Output is correct
8 Correct 50 ms 11172 KB Output is correct
9 Correct 83 ms 12788 KB Output is correct
10 Correct 67 ms 12860 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4948 KB Output is correct
2 Correct 2 ms 4948 KB Output is correct
3 Correct 2 ms 4948 KB Output is correct
4 Correct 2 ms 4960 KB Output is correct
5 Correct 2 ms 4948 KB Output is correct
6 Correct 2 ms 4948 KB Output is correct
7 Correct 2 ms 4948 KB Output is correct
8 Correct 2 ms 4948 KB Output is correct
9 Correct 2 ms 4948 KB Output is correct
10 Correct 2 ms 4948 KB Output is correct
11 Correct 2 ms 4948 KB Output is correct
12 Correct 2 ms 4948 KB Output is correct
13 Correct 2 ms 4948 KB Output is correct
14 Correct 2 ms 5012 KB Output is correct
15 Correct 75 ms 12772 KB Output is correct
16 Correct 67 ms 12868 KB Output is correct
17 Correct 31 ms 9112 KB Output is correct
18 Correct 75 ms 12836 KB Output is correct
19 Correct 69 ms 12792 KB Output is correct
20 Correct 69 ms 12772 KB Output is correct
21 Correct 91 ms 12868 KB Output is correct
22 Correct 50 ms 11172 KB Output is correct
23 Correct 83 ms 12788 KB Output is correct
24 Correct 67 ms 12860 KB Output is correct
25 Correct 103 ms 10100 KB Output is correct
26 Correct 69 ms 11608 KB Output is correct
27 Correct 79 ms 11776 KB Output is correct
28 Correct 98 ms 11980 KB Output is correct
29 Correct 80 ms 11884 KB Output is correct
30 Correct 100 ms 12008 KB Output is correct
31 Correct 16 ms 5972 KB Output is correct
32 Correct 71 ms 11836 KB Output is correct
33 Correct 154 ms 13700 KB Output is correct
34 Correct 77 ms 12092 KB Output is correct
35 Correct 120 ms 13740 KB Output is correct
36 Correct 68 ms 11892 KB Output is correct
37 Correct 112 ms 13280 KB Output is correct
38 Correct 97 ms 12892 KB Output is correct
39 Correct 117 ms 13600 KB Output is correct
40 Correct 101 ms 13176 KB Output is correct
41 Correct 155 ms 13272 KB Output is correct
42 Correct 127 ms 13816 KB Output is correct
43 Correct 94 ms 12388 KB Output is correct
44 Correct 127 ms 13924 KB Output is correct
45 Correct 84 ms 12120 KB Output is correct
46 Correct 122 ms 13164 KB Output is correct