CSES - Aalto Competitive Programming 2024 - wk7 - Wed - Results
Submission details
Task:Airport
Sender:aalto2024h_001
Submission time:2024-10-23 17:45:14 +0300
Language:C++ (C++11)
Status:READY
Result:
Test results
testverdicttime
#1ACCEPTED0.00 sdetails
#20.00 sdetails
#3ACCEPTED0.00 sdetails
#4ACCEPTED0.00 sdetails
#50.00 sdetails
#6ACCEPTED0.00 sdetails
#7ACCEPTED0.00 sdetails
#8ACCEPTED0.00 sdetails
#9ACCEPTED0.00 sdetails
#10ACCEPTED0.00 sdetails
#11ACCEPTED0.00 sdetails
#120.00 sdetails
#130.00 sdetails

Compiler report

input/code.cpp: In function 'long long int maxflow(long long int, long long int)':
input/code.cpp:70:21: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
   70 |     while (new_flow = bfs(s, t, parent)) {
      |            ~~~~~~~~~^~~~~~~~~~~~~~~~~~~

Code

#include <bits/stdc++.h>

using namespace std;
#define int long long
#define vout(x) for(int i=0;i<(long long)x.size();i++) printf("%lld ",x[i]);

// g++ <filename>.cpp -g -Wall -Wextra -DDEBUG -o <executable>

// copied from: https://codeforces.com/blog/entry/79024
// === Debug macro starts here ===

int recur_depth = 0;
#ifdef DEBUG
#define dbg(x) {++recur_depth; auto x_=x; --recur_depth; cerr<<string(recur_depth, '\t')<<"\e[91m"<<__func__<<":"<<__LINE__<<"\t"<<#x<<" = "<<x_<<"\e[39m"<<endl;}
#else
#define dbg(x)
#endif
template<typename Ostream, typename Cont>
typename enable_if<is_same<Ostream,ostream>::value, Ostream&>::type operator<<(Ostream& os,  const Cont& v){
	os<<"[";
	for(auto& x:v){os<<x<<", ";}
	return os<<"]";
}
template<typename Ostream, typename ...Ts>
Ostream& operator<<(Ostream& os,  const pair<Ts...>& p){
	return os<<"{"<<p.first<<", "<<p.second<<"}";
}

// === Debug macro ends here ===

const int INF = LONG_MAX;

int n, m;
const int maxN = 101; 
const int maxM = 1001;
int capacity[maxN][maxN];
vector<int> adj[maxN];

int bfs(int s, int t, vector<int>& parent) {
    
    fill(parent.begin(), parent.end(), -1);
    parent[s] = -2;
    queue<pair<int, int>> q;
    q.push({s, INF});

    while (!q.empty()) {
        int cur = q.front().first;
        int flow = q.front().second;
        q.pop();

        for (int next : adj[cur]) {
            if (parent[next] == -1 && capacity[cur][next]) {
                parent[next] = cur;
                int new_flow = min(flow, capacity[cur][next]);
                if (next == t) 
                    return new_flow;
                q.push({next, new_flow});
            }
        }
    }
    return 0;
}

int maxflow(int s, int t) {

    int flow = 0;
    vector<int> parent(n + 1);

    int new_flow;
    while (new_flow = bfs(s, t, parent)) {
        flow += new_flow;
        int cur = t;
        while (cur != s) {
            int prev = parent[cur];
            capacity[prev][cur] -= new_flow;
            capacity[cur][prev] += new_flow;
            cur = prev;
        }
    }
    return flow;
}

signed main() {

    cin >> n >> m;

    int checkpoint_cap[n+1];

    for (int i = 1; i <= n; i++) {
        int a;
        cin >> a; 
        checkpoint_cap[i] = a;
    } 

    // int max_cap = *std::max_element(checkpoint_cap.begin(), checkpoint_cap.end());

    // capacity.assign(n + 1, vector<int>(n + 1, 0));
    // adj.resize(n + 1);

    for (int i = 0; i < m; i++) {
        int a, b;
        cin >> a >> b;
        adj[a].push_back(b);
        adj[b].push_back(a);

        int cap = checkpoint_cap[b];
        if (cap == -1) cap = INF;
        capacity[a][b] += cap;
    }

    int source = 1;
    int sink = n;
    cout << maxflow(source, sink) << "\n";

    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:

input
10 20
-1 80 77 57 77 95 63 98 30 -1
6 7
8 9
7 8
...

correct output
30

user output
60

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:

input
10 20
-1 43 38 -1 7 54 26 97 76 -1
3 9
9 10
6 7
...

correct output
76

user output
126

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:

input
3 4
-1 1 -1
1 2
1 2
2 3
...

correct output
1

user output
-2

Test 13

Verdict:

input
7 8
-1 1 1 1 1 1 -1
1 2
1 3
2 4
...

correct output
1

user output
2