Submission details
Task:Airport
Sender:aalto25h_004
Submission time:2025-10-22 17:47:53 +0300
Language:C++ (C++17)
Status:READY
Result:
Test results
testverdicttime
#10.00 sdetails
#20.00 sdetails
#30.00 sdetails
#40.00 sdetails
#50.00 sdetails
#60.00 sdetails
#70.00 sdetails
#80.00 sdetails
#90.00 sdetails
#100.00 sdetails
#110.00 sdetails
#120.00 sdetails
#130.00 sdetails

Compiler report

input/code.cpp: In function 'int main()':
input/code.cpp:59:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   59 |     freopen("input.txt", "r", stdin); // TODO: REMOVE THIS YOU STUPID ****
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~

Code

#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <climits>

typedef long long ll;

using namespace std;

struct Edge {
    int to;
    ll cap;
    int rev; // index of reverse edge in G[to]
    bool is_rev;
};

const ll INF = (1LL << 60);
vector<vector<Edge> > graph;
vector<bool> used;


ll dfs(int v, int t, ll f, ll delta) {
    if (v == t) return f;
    used[v] = true;
    for (auto &e: graph[v]) {
        if (!used[e.to] && e.cap >= delta) {
            ll pushed = dfs(e.to, t, min(f, e.cap), delta);
            if (pushed > 0) {
                e.cap -= pushed;
                graph[e.to][e.rev].cap += pushed;
                return pushed;
            }
        }
    }
    return 0;
}

void mark_reachable(int v, vector<char> &reach) {
    reach[v] = 1;
    for (auto &e: graph[v]) {
        if (e.cap > 0 && !reach[e.to]) {
            mark_reachable(e.to, reach);
        }
    }
}

void add_edge(int u, int v, ll cap) {
    Edge a = {v, cap, (int)graph[v].size(), false};
    Edge b = {u, 0,   (int)graph[u].size(), true};
    graph[u].push_back(a);
    graph[v].push_back(b);
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    freopen("input.txt", "r", stdin); // TODO: REMOVE THIS YOU STUPID ****

    int n_orig, m;
    cin >> n_orig >> m;

    int N = 2 * n_orig;
    graph = vector<vector<Edge> >(N);

    vector<ll> r(n_orig + 1);
    ll maxFinite = 0;
    for (int i = 1; i <= n_orig; ++i) {
        cin >> r[i];
        if (r[i] != -1) maxFinite = max(maxFinite, r[i]);
    }

    for (int i = 1; i <= n_orig; ++i) {
        int in = 2 * (i - 1);
        int out = in + 1;
        ll cap = (r[i] == -1 ? INF : r[i]);
        add_edge(in, out, cap);
    }

    for (int i = 0; i < m; ++i) {
        int a, b;
        cin >> a >> b;
        int a_out = 2 * (a - 1) + 1;
        int b_in  = 2 * (b - 1);
        add_edge(a_out, b_in, INF);
    }

    int s = 1;
    int t = 2 * (n_orig - 1);

    ll delta = 1;
    if (maxFinite == 0) delta = 1;
    else {
        while (delta <= maxFinite) delta <<= 1;
        delta >>= 1;
        if (delta == 0) delta = 1;
    }

    ll maxflow = 0;
    while (delta > 0) {
        while (true) {
            used.assign(N, false);
            ll f = dfs(s, t, INF, delta);
            if (f == 0) break;
            maxflow += f;
        }
        delta >>= 1;
    }

    cout << maxflow << "\n";
    return 0;
}

Test details

Test 1

Verdict:

input
10 20
-1 85 7 19 90 72 11 46 65 -1
6 7
9 7
8 4
...

correct output
7

user output
(empty)

Error:
terminate called after throwing an instance of 'std::length_error'
  what():  cannot create std::vector larger than max_size()

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
(empty)

Error:
terminate called after throwing an instance of 'std::length_error'
  what():  cannot create std::vector larger than max_size()

Test 3

Verdict:

input
10 20
-1 63 16 42 62 70 9 94 68 -1
10 9
6 8
10 6
...

correct output
25

user output
(empty)

Error:
terminate called after throwing an instance of 'std::length_error'
  what():  cannot create std::vector larger than max_size()

Test 4

Verdict:

input
10 20
-1 3 86 -1 32 34 9 50 -1 -1
6 7
7 8
9 2
...

correct output
3

user output
(empty)

Error:
terminate called after throwing an instance of 'std::length_error'
  what():  cannot create std::vector larger than max_size()

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
(empty)

Error:
terminate called after throwing an instance of 'std::length_error'
  what():  cannot create std::vector larger than max_size()

Test 6

Verdict:

input
100 1000
-1 425576195 274150382 1021768...

correct output
6091126630

user output
(empty)

Error:
terminate called after throwing an instance of 'std::length_error'
  what():  cannot create std::vector larger than max_size()

Test 7

Verdict:

input
100 1000
-1 769953265 -1 389517741 2323...

correct output
769953265

user output
(empty)

Error:
terminate called after throwing an instance of 'std::length_error'
  what():  cannot create std::vector larger than max_size()

Test 8

Verdict:

input
100 1000
-1 584988267 763129662 6781413...

correct output
1699511766

user output
(empty)

Error:
terminate called after throwing an instance of 'std::length_error'
  what():  cannot create std::vector larger than max_size()

Test 9

Verdict:

input
100 1000
-1 921671366 121044688 2933366...

correct output
1805833567

user output
(empty)

Error:
terminate called after throwing an instance of 'std::length_error'
  what():  cannot create std::vector larger than max_size()

Test 10

Verdict:

input
100 1000
-1 763842763 612011030 4532521...

correct output
3342235784

user output
(empty)

Error:
terminate called after throwing an instance of 'std::length_error'
  what():  cannot create std::vector larger than max_size()

Test 11

Verdict:

input
3 3
-1 1 -1
1 2
2 3
2 2

correct output
1

user output
(empty)

Error:
terminate called after throwing an instance of 'std::length_error'
  what():  cannot create std::vector larger than max_size()

Test 12

Verdict:

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

correct output
1

user output
(empty)

Error:
terminate called after throwing an instance of 'std::length_error'
  what():  cannot create std::vector larger than max_size()

Test 13

Verdict:

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

correct output
1

user output
(empty)

Error:
terminate called after throwing an instance of 'std::length_error'
  what():  cannot create std::vector larger than max_size()