Task: | Airport |
Sender: | aalto2024h_006 |
Submission time: | 2024-10-23 17:21:02 +0300 |
Language: | C++ (C++20) |
Status: | READY |
Result: | ACCEPTED |
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 | ACCEPTED | 0.00 s | details |
#6 | ACCEPTED | 0.01 s | details |
#7 | ACCEPTED | 0.00 s | details |
#8 | ACCEPTED | 0.00 s | details |
#9 | ACCEPTED | 0.00 s | details |
#10 | ACCEPTED | 0.01 s | details |
#11 | ACCEPTED | 0.00 s | details |
#12 | ACCEPTED | 0.00 s | details |
#13 | ACCEPTED | 0.00 s | details |
Compiler report
input/code.cpp: In member function 'LL EK::Maxflow(LL, LL)': input/code.cpp:48:26: warning: comparison of integer expressions of different signedness: 'LL' {aka 'long long int'} and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare] 48 | for (LL i = 0; i < G[x].size(); i++) { | ~~^~~~~~~~~~~~~
Code
#include<bits/stdc++.h> using namespace std; typedef long long LL; const LL N=1005, INF=0x7ffffffffffffff; struct Edge { LL from, to, cap, flow; Edge(LL u, LL v, LL c, LL f) : from(u), to(v), cap(c), flow(f) {} }; vector<vector<LL> > ans; struct EK { LL n, m; vector<Edge> edges; vector<LL> G[N]; LL a[N], p[N]; // a:点 x -> BFS 过程中最近接近点 x 的边给它的最大流 // p:点 x -> BFS 过程中最近接近点 x 的边 void init(LL n_) { n = n_; for (LL i = 0; i < n; i++) G[i].clear(); edges.clear(); } void AddEdge(LL from, LL to, LL 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); } LL Maxflow(LL s, LL t) { LL flow = 0; while(true) { memset(a, 0, sizeof(a)); queue<LL> Q; Q.push(s); a[s] = INF; while (!Q.empty()) { LL x = Q.front(); Q.pop(); for (LL 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 (LL 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() { LL n, m; cin >> n >> m; graph.init(2*n); for(LL i=1; i<=n; i++) { LL x; cin >> x; if(x == -1) x = INF; graph.AddEdge(i, i+n, x); } // n -> n-in // n+n -> n-out while(m--) { LL u, v; cin >> u >> v; graph.AddEdge(u+n, v, INF); } cout << graph.Maxflow(1, n+n) << endl; return 0; }
Test details
Test 1
Verdict: ACCEPTED
input |
---|
10 20 -1 85 7 19 90 72 11 46 65 -1 6 7 9 7 8 4 ... |
correct output |
---|
7 |
user output |
---|
7 |
Test 2
Verdict: ACCEPTED
input |
---|
10 20 -1 80 77 57 77 95 63 98 30 -1 6 7 8 9 7 8 ... |
correct output |
---|
30 |
user output |
---|
30 |
Test 3
Verdict: ACCEPTED
input |
---|
10 20 -1 63 16 42 62 70 9 94 68 -1 10 9 6 8 10 6 ... |
correct output |
---|
25 |
user output |
---|
25 |
Test 4
Verdict: ACCEPTED
input |
---|
10 20 -1 3 86 -1 32 34 9 50 -1 -1 6 7 7 8 9 2 ... |
correct output |
---|
3 |
user output |
---|
3 |
Test 5
Verdict: ACCEPTED
input |
---|
10 20 -1 43 38 -1 7 54 26 97 76 -1 3 9 9 10 6 7 ... |
correct output |
---|
76 |
user output |
---|
76 |
Test 6
Verdict: ACCEPTED
input |
---|
100 1000 -1 425576195 274150382 1021768... |
correct output |
---|
6091126630 |
user output |
---|
6091126630 |
Test 7
Verdict: ACCEPTED
input |
---|
100 1000 -1 769953265 -1 389517741 2323... |
correct output |
---|
769953265 |
user output |
---|
769953265 |
Test 8
Verdict: ACCEPTED
input |
---|
100 1000 -1 584988267 763129662 6781413... |
correct output |
---|
1699511766 |
user output |
---|
1699511766 |
Test 9
Verdict: ACCEPTED
input |
---|
100 1000 -1 921671366 121044688 2933366... |
correct output |
---|
1805833567 |
user output |
---|
1805833567 |
Test 10
Verdict: ACCEPTED
input |
---|
100 1000 -1 763842763 612011030 4532521... |
correct output |
---|
3342235784 |
user output |
---|
3342235784 |
Test 11
Verdict: ACCEPTED
input |
---|
3 3
-1 1 -1 1 2 2 3 2 2 |
correct output |
---|
1 |
user output |
---|
1 |
Test 12
Verdict: ACCEPTED
input |
---|
3 4
-1 1 -1 1 2 1 2 2 3 ... |
correct output |
---|
1 |
user output |
---|
1 |
Test 13
Verdict: ACCEPTED
input |
---|
7 8 -1 1 1 1 1 1 -1 1 2 1 3 2 4 ... |
correct output |
---|
1 |
user output |
---|
1 |