Task: | Distinct Routes |
Sender: | minghao |
Submission time: | 2024-10-21 17:49:32 +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.00 s | details |
#5 | ACCEPTED | 0.00 s | details |
#6 | ACCEPTED | 0.00 s | details |
#7 | ACCEPTED | 0.00 s | details |
#8 | ACCEPTED | 0.00 s | details |
#9 | ACCEPTED | 0.00 s | details |
#10 | ACCEPTED | 0.00 s | details |
#11 | ACCEPTED | 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 | ACCEPTED | 0.01 s | details |
Compiler report
input/code.cpp: In member function 'int EK::Maxflow(int, int)': input/code.cpp:48:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare] 48 | for (int i = 0; i < G[x].size(); i++) { | ~~^~~~~~~~~~~~~
Code
#include<bits/stdc++.h> using namespace std; typedef long long LL; const int N=10005, INF=0x3f3f3f3f; struct Edge { int from, to, cap, flow; Edge(int u, int v, int c, int f) : from(u), to(v), cap(c), flow(f) {} }; vector<vector<int> > ans; struct EK { int n, m; vector<Edge> edges; vector<int> G[N]; int a[N], p[N]; // a:点 x -> BFS 过程中最近接近点 x 的边给它的最大流 // p:点 x -> BFS 过程中最近接近点 x 的边 void init(int n_) { n = n_; for (int i = 0; i < n; i++) G[i].clear(); edges.clear(); } void AddEdge(int from, int to, int cap) { edges.push_back(Edge(from, to, cap, 0)); edges.push_back(Edge(to, from, 0, 0)); m = edges.size(); G[from].push_back(m - 2); G[to].push_back(m - 1); } int Maxflow(int s, int t) { int flow = 0; while(true) { memset(a, 0, sizeof(a)); queue<int> Q; Q.push(s); a[s] = INF; while (!Q.empty()) { int x = Q.front(); Q.pop(); for (int i = 0; i < G[x].size(); i++) { // 遍历以 x 作为起点的边 Edge& e = edges[G[x][i]]; if (!a[e.to] && e.cap > e.flow) { // G[x][i] 是最近接近点 e.to 的边 p[e.to] = G[x][i]; // 最近接近点 e.to 的边赋给它的流 a[e.to] = min(a[x], e.cap - e.flow); Q.push(e.to); } } if (a[t]) break; } // 如果汇点没有接受到流,说明源点和汇点不在同一个连通分量上 if (!a[t]) break; for (int u = t; u != s; u = edges[p[u]].from) { // 通过 u 追寻 BFS 过程中 s -> t 的路径 edges[p[u]].flow += a[t]; edges[p[u] ^ 1].flow -= a[t]; } flow += a[t]; } return flow; } }graph; int main() { int n, m; cin >> n >> m; graph.init(n); while(m--) { int u, v; cin >> u >> v; graph.AddEdge(u, v, 1); } cout << graph.Maxflow(1, n) << endl; // Route for(auto x:graph.G[1]) { if(graph.edges[x].flow != 1) continue; vector<int> ans; ans.push_back(1); for(int u = graph.edges[x].to; u!=n;) { ans.push_back(u); for(auto e: graph.G[u]) { if(e <=0 || e >= graph.m) continue; Edge& edge = graph.edges[e]; if(edge.flow == 1) u = edge.to; } } ans.push_back(n); cout << ans.size() << endl; for(auto x: ans) cout << x << " "; putchar('\n'); } 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 ... 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: ACCEPTED
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 |
---|
21 3 1 35 40 3 1 3 40 ... Truncated |
Test 7
Verdict: ACCEPTED
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 |
---|
12 5 1 29 49 14 75 4 1 70 12 75 ... Truncated |
Test 8
Verdict: ACCEPTED
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 |
---|
9 4 1 35 23 100 5 1 62 25 28 100 ... Truncated |
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: ACCEPTED
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 |
---|
2 5 1 2 6 7 8 5 1 4 5 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 7 1 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 |
---|
3 3 1 2 7 4 1 3 5 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 |
---|
2 4 1 2 5 7 4 1 4 5 7 |
Test 15
Verdict: ACCEPTED
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 |
---|
116 5 1 129 142 473 500 5 1 63 158 171 500 ... Truncated |