Submission #782546

# Submission time Handle Problem Language Result Execution time Memory
782546 2023-07-14T04:52:23 Z andecaandeci Naboj (COCI22_naboj) C++17
110 / 110
511 ms 16136 KB
#include <bits/stdc++.h>
using namespace std;

const int lim = 200005;
int degree[lim], n, m, a, b, totdeg;
vector<int> adjl[lim];
vector<int> seq;
bool vis[lim];

int main() {
  cin >> n >> m;
  for (int i = 1; i <= m; i++) {
    cin >> a >> b;
    adjl[b].push_back(a);
    degree[a]++;
    totdeg++;
  }

  queue<int> q;

  for (int i = 1; i <= n; i++) {
    // cout << i << " " << degree[i] << endl;
    if (degree[i] == 0) {
      q.push(i);
      seq.push_back(i);
    }
  }
  // cout << totdeg << endl;

  while (!q.empty()) {
    int cur = q.front();
    q.pop();

    for (auto i: adjl[cur]) {
      degree[i]--;
      totdeg--;
      if (!vis[i]) {
        if (degree[i] == 0) {
          q.push(i);
          seq.push_back(i);
        }
      }
    }
  }

  // cout << totdeg << endl;
  if (totdeg > 0) cout << -1 << endl;
  else {
    cout << seq.size() << endl;
    for (auto i: seq) {
      cout << i << " " << 1 << endl;
    }
  }
}
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 3 ms 4948 KB Output is correct
3 Correct 3 ms 4948 KB Output is correct
4 Correct 3 ms 4948 KB Output is correct
5 Correct 3 ms 5004 KB Output is correct
6 Correct 3 ms 5004 KB Output is correct
7 Correct 3 ms 4948 KB Output is correct
8 Correct 3 ms 4948 KB Output is correct
9 Correct 2 ms 4948 KB Output is correct
10 Correct 3 ms 4948 KB Output is correct
11 Correct 3 ms 4948 KB Output is correct
12 Correct 3 ms 5004 KB Output is correct
13 Correct 2 ms 4948 KB Output is correct
14 Correct 3 ms 5032 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 326 ms 13868 KB Output is correct
2 Correct 337 ms 13868 KB Output is correct
3 Correct 169 ms 9488 KB Output is correct
4 Correct 340 ms 13792 KB Output is correct
5 Correct 334 ms 13636 KB Output is correct
6 Correct 345 ms 13816 KB Output is correct
7 Correct 344 ms 13740 KB Output is correct
8 Correct 260 ms 11840 KB Output is correct
9 Correct 342 ms 13672 KB Output is correct
10 Correct 386 ms 13764 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 3 ms 4948 KB Output is correct
3 Correct 3 ms 4948 KB Output is correct
4 Correct 3 ms 4948 KB Output is correct
5 Correct 3 ms 5004 KB Output is correct
6 Correct 3 ms 5004 KB Output is correct
7 Correct 3 ms 4948 KB Output is correct
8 Correct 3 ms 4948 KB Output is correct
9 Correct 2 ms 4948 KB Output is correct
10 Correct 3 ms 4948 KB Output is correct
11 Correct 3 ms 4948 KB Output is correct
12 Correct 3 ms 5004 KB Output is correct
13 Correct 2 ms 4948 KB Output is correct
14 Correct 3 ms 5032 KB Output is correct
15 Correct 326 ms 13868 KB Output is correct
16 Correct 337 ms 13868 KB Output is correct
17 Correct 169 ms 9488 KB Output is correct
18 Correct 340 ms 13792 KB Output is correct
19 Correct 334 ms 13636 KB Output is correct
20 Correct 345 ms 13816 KB Output is correct
21 Correct 344 ms 13740 KB Output is correct
22 Correct 260 ms 11840 KB Output is correct
23 Correct 342 ms 13672 KB Output is correct
24 Correct 386 ms 13764 KB Output is correct
25 Correct 193 ms 11200 KB Output is correct
26 Correct 152 ms 12536 KB Output is correct
27 Correct 218 ms 12768 KB Output is correct
28 Correct 302 ms 12944 KB Output is correct
29 Correct 153 ms 12600 KB Output is correct
30 Correct 237 ms 12996 KB Output is correct
31 Correct 38 ms 6384 KB Output is correct
32 Correct 366 ms 15820 KB Output is correct
33 Correct 470 ms 15972 KB Output is correct
34 Correct 362 ms 15880 KB Output is correct
35 Correct 501 ms 15880 KB Output is correct
36 Correct 376 ms 15880 KB Output is correct
37 Correct 462 ms 15880 KB Output is correct
38 Correct 429 ms 15820 KB Output is correct
39 Correct 476 ms 15968 KB Output is correct
40 Correct 442 ms 15876 KB Output is correct
41 Correct 453 ms 15784 KB Output is correct
42 Correct 488 ms 16136 KB Output is correct
43 Correct 380 ms 15768 KB Output is correct
44 Correct 511 ms 16064 KB Output is correct
45 Correct 349 ms 15868 KB Output is correct
46 Correct 448 ms 15868 KB Output is correct