Task: | Distinct Routes |
Sender: | Niilo |
Submission time: | 2024-10-21 16:50:33 +0300 |
Language: | C++ (C++17) |
Status: | READY |
Result: | RUNTIME ERROR |
test | verdict | time | |
---|---|---|---|
#1 | ACCEPTED | 0.00 s | details |
#2 | ACCEPTED | 0.00 s | details |
#3 | ACCEPTED | 0.01 s | details |
#4 | ACCEPTED | 0.01 s | details |
#5 | ACCEPTED | 0.00 s | details |
#6 | RUNTIME ERROR | 0.00 s | details |
#7 | RUNTIME ERROR | 0.01 s | details |
#8 | RUNTIME ERROR | 0.00 s | details |
#9 | ACCEPTED | 0.00 s | details |
#10 | ACCEPTED | 0.00 s | details |
#11 | RUNTIME ERROR | 0.00 s | details |
#12 | ACCEPTED | 0.00 s | details |
#13 | ACCEPTED | 0.00 s | details |
#14 | RUNTIME ERROR | 0.00 s | details |
#15 | RUNTIME ERROR | 0.01 s | details |
Code
#include <bits/stdc++.h> using namespace std; using ll = long long; const int N = 500; int W[N][N], W2[N][N]; vector<int> V[N]; int n, m; bool Z[N]; ll dfs(int i, ll c, ll w0) { if (i == n-1) { return w0; } if (Z[i]) return 0; Z[i] = 1; for (int j : V[i]) { ll w = W[i][j]; if (w >= c) { ll v = dfs(j,c,min(w0,w)); if (v) { W[i][j] -= v; W[j][i] += v; return v; } } } return 0; } int main() { cin >> n >> m; for (int i = 0; i < m; ++i) { int a, b; cin >> a >> b; V[a-1].push_back(b-1); V[b-1].push_back(a-1); W[a-1][b-1] += 1; ++W2[a-1][b-1]; } ll ans = 0; for (ll c = 1; c >= 1; c /= 2) { while (1) { memset(Z,0,n); ll w = dfs(0,c,1e18); if (w == 0) break; ans += w; } } cout << ans << '\n'; for (int i = 0; i < ans; ++i) { vector<int> P; P.push_back(0); while (P.back() != n-1) { int j = P.back(); for (int k : V[j]) { if (W2[j][k]) { P.push_back(k); --W2[j][k]; break; } } assert(P.back() != j); } cout << P.size() << '\n'; for (int j : P) { cout << j+1 << ' '; } cout << '\n'; } }
Test details
Test 1
Verdict: ACCEPTED
input |
---|
2 1 1 2 |
correct output |
---|
1 2 1 2 |
user output |
---|
1 2 1 2 |
Test 2
Verdict: ACCEPTED
input |
---|
4 2 1 2 3 4 |
correct output |
---|
0 |
user output |
---|
0 |
Test 3
Verdict: ACCEPTED
input |
---|
500 996 1 2 2 500 1 3 3 500 ... |
correct output |
---|
498 3 1 2 500 3 1 3 500 ... |
user output |
---|
498 3 1 2 500 3 1 3 500 ... Truncated |
Test 4
Verdict: ACCEPTED
input |
---|
500 499 1 2 2 3 3 4 4 5 ... |
correct output |
---|
1 500 1 2 3 4 5 6 7 8 9 10 11 12 13 ... |
user output |
---|
1 500 1 2 3 4 5 6 7 8 9 10 11 12 13 ... Truncated |
Test 5
Verdict: ACCEPTED
input |
---|
2 1 2 1 |
correct output |
---|
0 |
user output |
---|
0 |
Test 6
Verdict: RUNTIME ERROR
input |
---|
40 1000 25 22 15 24 7 33 16 32 ... |
correct output |
---|
21 44 1 35 39 34 29 32 22 38 20 30 1... |
user output |
---|
(empty) |
Error:
code: input/code.cpp:63: int main(): Assertion `P.back() != j' failed.
Test 7
Verdict: RUNTIME ERROR
input |
---|
75 1000 72 6 46 66 63 45 70 46 ... |
correct output |
---|
12 30 1 29 24 9 18 63 45 31 66 72 6 ... |
user output |
---|
(empty) |
Error:
code: input/code.cpp:63: int main(): Assertion `P.back() != j' failed.
Test 8
Verdict: RUNTIME ERROR
input |
---|
100 1000 75 97 7 62 88 25 36 44 ... |
correct output |
---|
9 51 1 35 15 86 79 34 43 94 83 75 9... |
user output |
---|
(empty) |
Error:
code: input/code.cpp:63: int main(): Assertion `P.back() != j' failed.
Test 9
Verdict: ACCEPTED
input |
---|
3 2 1 2 2 3 |
correct output |
---|
1 3 1 2 3 |
user output |
---|
1 3 1 2 3 |
Test 10
Verdict: ACCEPTED
input |
---|
11 12 1 2 2 3 3 4 4 5 ... |
correct output |
---|
2 6 1 2 3 4 5 11 7 1 6 7 8 9 10 11 |
user output |
---|
2 6 1 2 3 4 5 11 7 1 6 7 8 9 10 11 |
Test 11
Verdict: RUNTIME ERROR
input |
---|
8 9 1 2 2 3 3 8 1 4 ... |
correct output |
---|
2 5 1 2 6 7 8 5 1 4 5 3 8 |
user output |
---|
(empty) |
Error:
code: input/code.cpp:63: int main(): Assertion `P.back() != j' failed.
Test 12
Verdict: ACCEPTED
input |
---|
8 9 1 2 1 3 2 3 3 4 ... |
correct output |
---|
1 8 1 2 3 4 5 6 7 8 |
user output |
---|
1 8 1 2 3 4 5 6 7 8 |
Test 13
Verdict: ACCEPTED
input |
---|
7 9 1 2 1 3 2 7 3 4 ... |
correct output |
---|
3 3 1 2 7 4 1 3 5 7 ... |
user output |
---|
3 3 1 2 7 4 1 3 4 7 ... |
Test 14
Verdict: RUNTIME ERROR
input |
---|
7 15 3 6 5 2 5 4 3 5 ... |
correct output |
---|
2 5 1 2 3 6 7 4 1 4 5 7 |
user output |
---|
(empty) |
Error:
code: input/code.cpp:63: int main(): Assertion `P.back() != j' failed.
Test 15
Verdict: RUNTIME ERROR
input |
---|
500 986 244 252 224 22 81 484 273 432 ... |
correct output |
---|
116 5 1 129 142 473 500 5 1 63 158 171 500 ... |
user output |
---|
(empty) |
Error:
code: input/code.cpp:63: int main(): Assertion `P.back() != j' failed.