| Task: | Distinct Routes |
| Sender: | aalto26gm_026 |
| Submission time: | 2026-10-19 17:48:12 +0300 |
| Language: | C++ (C++20) |
| Status: | READY |
| Result: | WRONG ANSWER |
| 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 | WRONG ANSWER | 0.00 s | details |
| #7 | WRONG ANSWER | 0.00 s | details |
| #8 | WRONG ANSWER | 0.00 s | details |
| #9 | ACCEPTED | 0.00 s | details |
| #10 | WRONG ANSWER | 0.00 s | details |
| #11 | WRONG ANSWER | 0.00 s | details |
| #12 | ACCEPTED | 0.00 s | details |
| #13 | WRONG ANSWER | 0.00 s | details |
| #14 | WRONG ANSWER | 0.00 s | details |
| #15 | WRONG ANSWER | 0.01 s | details |
Code
#include <bits/stdc++.h>
using namespace std;
// debug
template<class T> ostream& operator<<(ostream&, const vector<T>&);
template<class T> ostream& operator<<(ostream&, const set<T>&);
template<class T> ostream& operator<<(ostream&, const multiset<T>&);
template<class K, class V> ostream& operator<<(ostream&, const map<K, V>&);
template<class T, size_t N> ostream& operator<<(ostream&, const array<T, N>&);
template<class A, class B> ostream& operator<<(ostream& os, const pair<A, B>& p) { return os << "(" << p.first << ", " << p.second << ")"; }
template<class T>
void print_collection(ostream& os, const T& v) {
os << "{";
bool first = true;
for (const auto& x : v) {
if (!first) os << ", ";
first = false;
os << x;
}
os << "}";
}
template<class T> ostream& operator<<(ostream& os, const vector<T>& v) { print_collection(os, v); return os; }
template<class T> ostream& operator<<(ostream& os, const set<T>& v) { print_collection(os, v); return os; }
template<class T> ostream& operator<<(ostream& os, const multiset<T>& v) { print_collection(os, v); return os; }
template<class K, class V> ostream& operator<<(ostream& os, const map<K, V>& v) { print_collection(os, v); return os; }
template<class T, size_t N> ostream& operator<<(ostream& os, const array<T, N>& v) { print_collection(os, v); return os; }
#define dbg(x) cerr << #x << " = " << (x) << '\n'
using ll = long long;
constexpr int INF = 1'000'000'000; // 1e9
constexpr ll LINF = 1'000'000'000'000'000'000LL; // 1e18
constexpr int MOD = 1'000'000'007; // 1e9 + 7
inline ll add(ll a, ll b) { return (a + b) % MOD; }
inline ll sub(ll a, ll b) { return ((a - b) % MOD + MOD) % MOD; }
inline ll mul(ll a, ll b) { return (a * b) % MOD; }
void solve() {
int N, M;
cin >> N >> M;
vector<vector<int>> adj(N + 1);
vector<vector<int>> ad(N+1);
vector<vector<ll>> cap(N + 1, vector<ll>(N + 1, 0));
for (int i = 0; i < M; i++) {
int a, b;
cin >> a >> b;
adj[a].push_back(b);
adj[b].push_back(a);
ad[a].push_back(b);
cap[a][b] += 1;
}
vector<char> visited(N + 1, 0);
auto dfs = [&](auto&& dfs, int u, ll pushed) -> ll {
if (u == N) return pushed;
visited[u] = 1;
for (int v : adj[u]) {
if (visited[v]) continue;
ll f = dfs(dfs, v, min(pushed, cap[u][v]));
if (f > 0) {
cap[u][v] -= f;
cap[v][u] += f;
return f;
}
}
return 0;
};
ll flow = 0;
while (true) {
fill(visited.begin(), visited.end(), 0);
ll pushed = dfs(dfs, 1, LINF);
if (pushed == 0) break;
flow += pushed;
}
cout << flow << '\n';
while (flow-- > 0) {
vector<char> visited(N + 1, 0);
vector<int> path;
auto dfs = [&](auto&& dfs, int u) -> bool {
if (u == N) {
return true;
}
visited[u] = 1;
for (auto &v: ad[u]) {
if (v == -1 || visited[v]) continue;
bool f = dfs(dfs, v);
if (f) {
path.push_back(v);
v = -1;
return f;
}
}
return false;
};
dfs(dfs, 1);
cout << path.size() + 1 << "\n1";
for(int i = path.size() - 1; i >= 0; i--) {
cout << " " << path[i];
}
cout << "\n";
}
// ll flow = 0;
// while (true) {
// fill(visited.begin(), visited.end(), 0);
// ll pushed = dfs(dfs, 1, LINF);
// if (pushed == 0) break;
// flow += pushed;
// }
// cout << flow << '\n';
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
solve();
return 0;
}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 ... |
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 ... |
Test 5
Verdict: ACCEPTED
| input |
|---|
| 2 1 2 1 |
| correct output |
|---|
| 0 |
| user output |
|---|
| 0 |
Test 6
Verdict: WRONG ANSWER
| 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 |
|---|
| 0 |
Test 7
Verdict: WRONG ANSWER
| 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 |
|---|
| 0 |
Test 8
Verdict: WRONG ANSWER
| 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 |
|---|
| 1 87 1 35 15 86 79 67 13 41 52 6 58... |
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: WRONG ANSWER
| 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 |
|---|
| 1 6 1 2 3 4 5 11 |
Test 11
Verdict: WRONG ANSWER
| 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 |
|---|
| 1 4 1 2 3 8 |
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: WRONG ANSWER
| 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 |
|---|
| 2 3 1 2 7 4 1 3 4 7 |
Test 14
Verdict: WRONG ANSWER
| 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 |
|---|
| 1 5 1 2 3 6 7 |
Test 15
Verdict: WRONG ANSWER
| 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 |
|---|
| 19 5 1 129 142 473 500 5 1 63 158 171 500 ... |
