Task: | Longest route |
Sender: | aalto2024h_006 |
Submission time: | 2024-10-23 17:24:12 +0300 |
Language: | C++ (C++20) |
Status: | READY |
Result: | WRONG ANSWER |
test | verdict | time | |
---|---|---|---|
#1 | WRONG ANSWER | 0.00 s | details |
#2 | WRONG ANSWER | 0.00 s | details |
#3 | WRONG ANSWER | 0.00 s | details |
#4 | ACCEPTED | 0.00 s | details |
#5 | ACCEPTED | 0.00 s | details |
#6 | ACCEPTED | 0.07 s | details |
#7 | RUNTIME ERROR | 0.82 s | details |
#8 | RUNTIME ERROR | 0.78 s | details |
#9 | OUTPUT LIMIT EXCEEDED | 0.00 s | details |
#10 | WRONG ANSWER | 0.83 s | details |
#11 | WRONG ANSWER | 0.06 s | details |
#12 | RUNTIME ERROR | 0.45 s | details |
#13 | ACCEPTED | 0.00 s | details |
#14 | ACCEPTED | 0.00 s | details |
#15 | RUNTIME ERROR | 0.79 s | details |
#16 | ACCEPTED | 0.00 s | details |
#17 | RUNTIME ERROR | 0.83 s | details |
#18 | ACCEPTED | 0.04 s | details |
#19 | ACCEPTED | 0.00 s | details |
#20 | RUNTIME ERROR | 0.42 s | details |
#21 | WRONG ANSWER | 0.00 s | details |
Code
#include <bits/stdc++.h> using namespace std; #define rep(i, a, b) for(int i = a; i < (b); ++i) #define all(x) begin(x), end(x) #define sz(x) (int)(x).size() #define int long long const int INF = 1e18; typedef pair<int, int> pii; typedef vector<int> vi; int n; vector<vector<int>> adj; vector<bool> visited; vector<int> ans; void dfs(int v) { visited[v] = true; for (int u : adj[v]) { if (!visited[u]) dfs(u); } ans.push_back(v); } void topological_sort() { visited.assign(n, false); ans.clear(); for (int i = 0; i < n; ++i) { if (!visited[i]) { dfs(i); } } reverse(ans.begin(), ans.end()); } bool bfs(int s, int e) { queue<int> q; vector<bool> used(n); q.push(s); used[s] = true; while (!q.empty()) { int v = q.front(); q.pop(); for (int u : adj[v]) { if (u == e){ return true; } if (!used[u]) { used[u] = true; q.push(u); } } } return false; } signed main() { cin.tie(0)->sync_with_stdio(0); cin.exceptions(cin.failbit); int m; cin >> n >> m; adj.resize(n); //adj2.resize(n); rep(i, 0, m){ int a, b; cin >> a >> b; adj[a-1].push_back(b-1); //adj2[b-1].push_back(a-1); } if (!bfs(0,n-1)){ cout << "IMPOSSIBLE"; return 0; } topological_sort(); vector<int> dist(n, -INF); dist[0] = 1; vector<vector<int>> sol(n); sol[0].push_back(1); for (int u : ans){ for (int v : adj[u]){ if (dist[v] < dist[u] + 1){ dist[v] = dist[u] + 1; sol[v].insert(sol[v].end(), sol[u].begin(), sol[u].end()); sol[v].push_back(v+1); } } } //set<int> s(sol[n-1].begin(), sol[n-1].end()); // for (int u : ans){ // cout << u << " "; // } // cout << endl; // for (int u : dist){ // cout << u << " "; // } // for (auto& u : sol){ // for (int v : u){ // cout << v << " "; // } // cout << endl; // } cout << dist[n-1] << endl; for (int u: sol[n-1]){ cout << u << " "; } return 0; }
Test details
Test 1
Verdict: WRONG ANSWER
input |
---|
10 10 2 6 1 2 4 6 5 6 ... |
correct output |
---|
5 1 2 5 6 10 |
user output |
---|
5 1 10 6 1 2 6 5 1 2 5 6 10 |
Test 2
Verdict: WRONG ANSWER
input |
---|
10 10 3 9 6 5 6 9 2 8 ... |
correct output |
---|
4 1 2 8 10 |
user output |
---|
4 10 8 1 2 8 10 |
Test 3
Verdict: WRONG ANSWER
input |
---|
10 10 5 10 4 10 8 7 7 10 ... |
correct output |
---|
3 1 4 10 |
user output |
---|
3 5 10 1 4 10 |
Test 4
Verdict: ACCEPTED
input |
---|
10 10 8 10 2 6 2 10 7 10 ... |
correct output |
---|
IMPOSSIBLE |
user output |
---|
IMPOSSIBLE |
Test 5
Verdict: ACCEPTED
input |
---|
10 10 8 4 2 10 1 3 4 9 ... |
correct output |
---|
5 1 8 7 2 10 |
user output |
---|
5 1 8 7 2 10 |
Test 6
Verdict: ACCEPTED
input |
---|
100000 200000 86085 57043 45527 29537 41919 84699 95993 82082 ... |
correct output |
---|
IMPOSSIBLE |
user output |
---|
IMPOSSIBLE |
Test 7
Verdict: RUNTIME ERROR
input |
---|
100000 200000 10961 53490 59843 36636 40674 66772 32618 41570 ... |
correct output |
---|
31 1 37239 44082 21537 90572 7332... |
user output |
---|
(empty) |
Test 8
Verdict: RUNTIME ERROR
input |
---|
100000 200000 87375 76468 38855 27547 49415 83191 38572 1524 ... |
correct output |
---|
35 1 91343 59014 56722 34054 3875... |
user output |
---|
(empty) |
Test 9
Verdict: OUTPUT LIMIT EXCEEDED
input |
---|
100000 200000 17973 70097 19982 80323 96486 2404 75650 63274 ... |
correct output |
---|
36 1 25685 90292 59380 91058 2663... |
user output |
---|
(empty) |
Test 10
Verdict: WRONG ANSWER
input |
---|
100000 200000 74343 53088 97443 7885 64807 58252 9374 33312 ... |
correct output |
---|
28 1 26390 15278 11333 48479 6881... |
user output |
---|
28 100000 58328 5646 4002 68103 6... Truncated |
Test 11
Verdict: WRONG ANSWER
input |
---|
100000 199998 1 100000 1 100000 2 100000 2 100000 ... |
correct output |
---|
2 1 100000 |
user output |
---|
2 100000 1 100000 |
Test 12
Verdict: RUNTIME ERROR
input |
---|
100000 199998 1 2 1 2 2 3 2 3 ... |
correct output |
---|
100000 1 2 3 4 5 6 7 8 9 10 11 12 13 ... |
user output |
---|
(empty) |
Test 13
Verdict: ACCEPTED
input |
---|
2 1 1 2 |
correct output |
---|
2 1 2 |
user output |
---|
2 1 2 |
Test 14
Verdict: ACCEPTED
input |
---|
5 4 1 2 2 3 3 4 1 5 |
correct output |
---|
2 1 5 |
user output |
---|
2 1 5 |
Test 15
Verdict: RUNTIME ERROR
input |
---|
99999 149997 1 3 3 5 5 7 7 9 ... |
correct output |
---|
99999 1 2 3 4 5 6 7 8 9 10 11 12 13 ... |
user output |
---|
(empty) |
Test 16
Verdict: ACCEPTED
input |
---|
3 2 1 3 3 2 |
correct output |
---|
2 1 3 |
user output |
---|
2 1 3 |
Test 17
Verdict: RUNTIME ERROR
input |
---|
99999 149997 1 2 2 4 4 6 6 8 ... |
correct output |
---|
99999 1 3 2 5 4 7 6 9 8 11 10 13 12 ... |
user output |
---|
(empty) |
Test 18
Verdict: ACCEPTED
input |
---|
100000 200000 1 2 1 3 1 4 1 5 ... |
correct output |
---|
IMPOSSIBLE |
user output |
---|
IMPOSSIBLE |
Test 19
Verdict: ACCEPTED
input |
---|
5 4 2 1 3 1 1 4 1 5 |
correct output |
---|
2 1 5 |
user output |
---|
2 1 5 |
Test 20
Verdict: RUNTIME ERROR
input |
---|
100000 99999 99999 100000 99998 99999 99997 99998 99996 99997 ... |
correct output |
---|
100000 1 2 3 4 5 6 7 8 9 10 11 12 13 ... |
user output |
---|
(empty) |
Test 21
Verdict: WRONG ANSWER
input |
---|
4 4 3 1 3 4 1 2 2 4 |
correct output |
---|
3 1 2 4 |
user output |
---|
3 4 1 2 4 |