Task: | Course Schedule |
Sender: | snude |
Submission time: | 2024-10-06 18:36:02 +0300 |
Language: | C++ (C++11) |
Status: | READY |
Result: | RUNTIME ERROR |
test | verdict | time | |
---|---|---|---|
#1 | ACCEPTED | 0.00 s | details |
#2 | ACCEPTED | 0.00 s | details |
#3 | ACCEPTED | 0.00 s | details |
#4 | ACCEPTED | 0.00 s | details |
#5 | RUNTIME ERROR | 0.43 s | details |
#6 | ACCEPTED | 0.17 s | details |
#7 | ACCEPTED | 0.17 s | details |
#8 | ACCEPTED | 0.17 s | details |
#9 | ACCEPTED | 0.17 s | details |
#10 | RUNTIME ERROR | 0.65 s | details |
#11 | ACCEPTED | 0.21 s | details |
#12 | RUNTIME ERROR | 0.41 s | details |
#13 | RUNTIME ERROR | 0.41 s | details |
#14 | ACCEPTED | 0.12 s | details |
#15 | ACCEPTED | 0.12 s | details |
#16 | RUNTIME ERROR | 0.41 s | details |
#17 | RUNTIME ERROR | 0.53 s | details |
Code
#include <algorithm> #include <cstdio> #include <iostream> #include <utility> #include <vector> #include <bits/stdc++.h> using namespace std; using ll = long long; // Debug printing #ifdef DEBUG #define deb(fmt, args...) printf("DEBUG: %d: " fmt, __LINE__, ##args) #else #define deb(fmt, args...) #endif vector<int> top_sort; bool impossible = false; void dfs(int s, vector<int> &status, vector<int> adj[]) { if (impossible) return; if (status[s] == 2) { return; }; status[s] = 1; for (auto u : adj[s]) { dfs(u, status, adj); } status[s] = 2; top_sort.push_back(s); } int main(int argc, char *argv[]) { // Read the input parameters int n, m; cin >> n >> m; // Read pairs from multiple lines vector<pair<int, int>> input_pairs(m); for (int i = 0; i < m; i++) { cin >> input_pairs[i].first >> input_pairs[i].second; } vector<int> adj[n + 1]; // Add edges to adjacent structure for (int j = 0; j < m; j++) { adj[input_pairs[j].first].push_back(input_pairs[j].second); } vector<int> status(n + 1, 0); for (int i = 1; i < n + 1; i++) { if (status[i] == 0) dfs(i, status, adj); } for (int i = n - 1; i >= 0; i--) { cout << top_sort[i] << " "; } cout << "\n"; return 0; }
Test details
Test 1
Verdict: ACCEPTED
input |
---|
10 20 5 2 2 4 8 9 6 4 ... |
correct output |
---|
5 7 10 2 1 8 3 9 6 4 |
user output |
---|
10 7 5 2 1 8 3 9 6 4 |
Test 2
Verdict: ACCEPTED
input |
---|
10 20 2 7 1 10 9 5 9 7 ... |
correct output |
---|
1 8 3 6 10 2 9 4 5 7 |
user output |
---|
8 1 3 6 10 2 9 4 5 7 |
Test 3
Verdict: ACCEPTED
input |
---|
10 20 8 5 2 3 10 1 9 1 ... |
correct output |
---|
4 6 7 9 10 2 8 3 1 5 |
user output |
---|
9 7 10 6 8 4 2 3 1 5 |
Test 4
Verdict: ACCEPTED
input |
---|
10 20 5 10 10 3 9 10 6 2 ... |
correct output |
---|
7 8 6 4 2 1 5 9 10 3 |
user output |
---|
8 7 6 4 2 5 1 9 10 3 |
Test 5
Verdict: RUNTIME ERROR
input |
---|
10 20 2 9 4 8 9 1 10 6 ... |
correct output |
---|
IMPOSSIBLE |
user output |
---|
(empty) |
Test 6
Verdict: ACCEPTED
input |
---|
100000 200000 78359 8853 18190 30703 11401 30087 34627 11535 ... |
correct output |
---|
2 3 8 9 16 18 21 22 27 34 36 4... |
user output |
---|
99998 99996 99994 99993 99992 ... Truncated |
Test 7
Verdict: ACCEPTED
input |
---|
100000 200000 32395 2098 67067 31866 31867 67167 78488 33397 ... |
correct output |
---|
9 11 13 16 22 35 37 38 40 44 5... |
user output |
---|
100000 99994 99991 99986 99983... Truncated |
Test 8
Verdict: ACCEPTED
input |
---|
100000 200000 19035 36947 13730 46121 99449 77790 15626 11731 ... |
correct output |
---|
1 7 15 17 18 34 38 41 48 49 51... |
user output |
---|
100000 99998 99996 99993 99992... Truncated |
Test 9
Verdict: ACCEPTED
input |
---|
100000 200000 14188 9709 46541 20871 32203 88809 99879 54779 ... |
correct output |
---|
6 10 11 16 17 19 21 22 23 28 3... |
user output |
---|
99996 99992 99991 99986 99985 ... Truncated |
Test 10
Verdict: RUNTIME ERROR
input |
---|
100000 200000 41882 61162 28138 18053 74649 74863 69760 74508 ... |
correct output |
---|
IMPOSSIBLE |
user output |
---|
(empty) |
Test 11
Verdict: ACCEPTED
input |
---|
100000 199998 1 100000 1 100000 2 100000 2 100000 ... |
correct output |
---|
1 2 3 4 5 6 7 8 9 10 11 12 13 ... |
user output |
---|
99999 99998 99997 99996 99995 ... Truncated |
Test 12
Verdict: RUNTIME ERROR
input |
---|
2 2 1 2 2 1 |
correct output |
---|
IMPOSSIBLE |
user output |
---|
(empty) |
Test 13
Verdict: RUNTIME ERROR
input |
---|
6 6 1 2 2 3 4 3 4 5 ... |
correct output |
---|
IMPOSSIBLE |
user output |
---|
(empty) |
Test 14
Verdict: ACCEPTED
input |
---|
99999 149997 1 3 3 5 5 7 7 9 ... |
correct output |
---|
1 2 3 4 5 6 7 8 9 10 11 12 13 ... |
user output |
---|
1 2 3 4 5 6 7 8 9 10 11 12 13 ... Truncated |
Test 15
Verdict: ACCEPTED
input |
---|
100000 149998 2 1 3 2 4 3 5 4 ... |
correct output |
---|
100000 99999 99998 99997 99996... |
user output |
---|
100000 99999 99998 99997 99996... Truncated |
Test 16
Verdict: RUNTIME ERROR
input |
---|
6 6 1 2 1 3 2 4 3 5 ... |
correct output |
---|
IMPOSSIBLE |
user output |
---|
(empty) |
Test 17
Verdict: RUNTIME ERROR
input |
---|
100000 200000 1 1 1 1 2 2 2 2 ... |
correct output |
---|
IMPOSSIBLE |
user output |
---|
(empty) |