답안 #644394

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
644394 2022-09-24T15:03:29 Z Iwanttobreakfree Naboj (COCI22_naboj) C++17
110 / 110
392 ms 21184 KB
#include <iostream>
#include <vector>
#include <queue>

using namespace std;

int main() {
    int n, m;
    cin >> n >> m;
    vector<vector<int>> g (n,vector<int>());
    while (m--) {
        int a, b;
        cin >> a >> b;
        a--;b--;
        g[b].push_back (a);
    }
    vector<int> cnt (n);
    for (int i = 0; i < n; ++i) for (int x :g[i]) cnt[x]++;
    queue<int> q;
    for (int i = 0; i < n; ++i) if(!cnt[i]) q.push(i);
    vector<int> ans;
    while (!q.empty()) {
        int u = q.front();
        ans.push_back (u);
        q.pop();
        for (int v:g[u]){
            cnt[v]--;
            if (!cnt[v])q.push (v);
        }
    }
    if (ans.size() == n) {
        cout << n << '\n';
        for (auto x : ans) cout << x+1 << ' ' << 1 << '\n';
    }
    else cout << -1;
}

Compilation message

naboj.cpp: In function 'int main()':
naboj.cpp:31:20: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   31 |     if (ans.size() == n) {
      |         ~~~~~~~~~~~^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 296 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 296 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 184 ms 15364 KB Output is correct
2 Correct 187 ms 15336 KB Output is correct
3 Correct 89 ms 8132 KB Output is correct
4 Correct 186 ms 15372 KB Output is correct
5 Correct 191 ms 15292 KB Output is correct
6 Correct 184 ms 15288 KB Output is correct
7 Correct 189 ms 15356 KB Output is correct
8 Correct 143 ms 11996 KB Output is correct
9 Correct 184 ms 15368 KB Output is correct
10 Correct 185 ms 15368 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 296 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 296 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 184 ms 15364 KB Output is correct
16 Correct 187 ms 15336 KB Output is correct
17 Correct 89 ms 8132 KB Output is correct
18 Correct 186 ms 15372 KB Output is correct
19 Correct 191 ms 15292 KB Output is correct
20 Correct 184 ms 15288 KB Output is correct
21 Correct 189 ms 15356 KB Output is correct
22 Correct 143 ms 11996 KB Output is correct
23 Correct 184 ms 15368 KB Output is correct
24 Correct 185 ms 15368 KB Output is correct
25 Correct 274 ms 13404 KB Output is correct
26 Correct 213 ms 15312 KB Output is correct
27 Correct 256 ms 16352 KB Output is correct
28 Correct 314 ms 17988 KB Output is correct
29 Correct 201 ms 14888 KB Output is correct
30 Correct 313 ms 17832 KB Output is correct
31 Correct 47 ms 2508 KB Output is correct
32 Correct 214 ms 17848 KB Output is correct
33 Correct 385 ms 20700 KB Output is correct
34 Correct 236 ms 18124 KB Output is correct
35 Correct 375 ms 20752 KB Output is correct
36 Correct 214 ms 17728 KB Output is correct
37 Correct 343 ms 20124 KB Output is correct
38 Correct 298 ms 19332 KB Output is correct
39 Correct 370 ms 20560 KB Output is correct
40 Correct 318 ms 19612 KB Output is correct
41 Correct 326 ms 19660 KB Output is correct
42 Correct 392 ms 21120 KB Output is correct
43 Correct 257 ms 18400 KB Output is correct
44 Correct 392 ms 21184 KB Output is correct
45 Correct 223 ms 17960 KB Output is correct
46 Correct 320 ms 19612 KB Output is correct