Submission details
Task:Airport
Sender:ind1f
Submission time:2025-10-22 17:33:48 +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

Code

#include <bits/stdc++.h>

using namespace std;

struct FlowEdge {
    int v, u;
    long long cap, flow = 0;
    FlowEdge(int v, int u, long long cap) : v(v), u(u), cap(cap) {}
};

struct Dinic {
    const long long flow_inf = 1e18;
    vector<FlowEdge> edges;
    vector<vector<int>> adj;
    int n, m = 0;
    int s, t;
    vector<int> level, ptr;
    queue<int> q;

    Dinic(int n, int s, int t) : n(n), s(s), t(t) {
        adj.resize(n);
        level.resize(n);
        ptr.resize(n);
    }

    void add_edge(int v, int u, long long cap) {
        edges.emplace_back(v, u, cap);
        edges.emplace_back(u, v, 0);
        adj[v].push_back(m);
        adj[u].push_back(m + 1);
        m += 2;
    }

    bool bfs() {
        while (!q.empty()) {
            int v = q.front();
            q.pop();
            for (int id : adj[v]) {
                if (edges[id].cap == edges[id].flow)
                    continue;
                if (level[edges[id].u] != -1)
                    continue;
                level[edges[id].u] = level[v] + 1;
                q.push(edges[id].u);
            }
        }
        return level[t] != -1;
    }

    long long dfs(int v, long long pushed) {
        if (pushed == 0)
            return 0;
        if (v == t)
            return pushed;
        for (int& cid = ptr[v]; cid < (int)adj[v].size(); cid++) {
            int id = adj[v][cid];
            int u = edges[id].u;
            if (level[v] + 1 != level[u])
                continue;
            long long tr = dfs(u, min(pushed, edges[id].cap - edges[id].flow));
            if (tr == 0)
                continue;
            edges[id].flow += tr;
            edges[id ^ 1].flow -= tr;
            return tr;
        }
        return 0;
    }

    long long flow() {
        long long f = 0;
        while (true) {
            fill(level.begin(), level.end(), -1);
            level[s] = 0;
            q.push(s);
            if (!bfs())
                break;
            fill(ptr.begin(), ptr.end(), 0);
            while (long long pushed = dfs(s, flow_inf)) {
                f += pushed;
            }
        }
        return f;
    }
};

int n, m;
int r[105];

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> m;
  Dinic d(300, 1, n);
  for (int i = 1; i <= n; i++) {
    cin >> r[i];
    d.add_edge(i, i + 101, (r[i] == -1 ? 1000000000000000 : r[i]));
  }
  while (m--) {
    int a, b;
    cin >> a >> b;
    d.add_edge(a + 101, b + 101, 1000000000000000);
  }
  cout << d.flow() << '\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
0

Feedback: Incorrect character on line 1 col 1: expected "7", got "0"

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
0

Feedback: Incorrect character on line 1 col 1: expected "30", got "0"

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
0

Feedback: Incorrect character on line 1 col 1: expected "25", got "0"

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
0

Feedback: Incorrect character on line 1 col 1: expected "3", got "0"

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
0

Feedback: Incorrect character on line 1 col 1: expected "76", got "0"

Test 6

Verdict:

input
100 1000
-1 425576195 274150382 1021768...

correct output
6091126630

user output
0

Feedback: Incorrect character on line 1 col 1: expected "6091126630", got "0"

Test 7

Verdict:

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

correct output
769953265

user output
0

Feedback: Incorrect character on line 1 col 1: expected "769953265", got "0"

Test 8

Verdict:

input
100 1000
-1 584988267 763129662 6781413...

correct output
1699511766

user output
0

Feedback: Incorrect character on line 1 col 1: expected "1699511766", got "0"

Test 9

Verdict:

input
100 1000
-1 921671366 121044688 2933366...

correct output
1805833567

user output
0

Feedback: Incorrect character on line 1 col 1: expected "1805833567", got "0"

Test 10

Verdict:

input
100 1000
-1 763842763 612011030 4532521...

correct output
3342235784

user output
0

Feedback: Incorrect character on line 1 col 1: expected "3342235784", got "0"

Test 11

Verdict:

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

correct output
1

user output
0

Feedback: Incorrect character on line 1 col 1: expected "1", got "0"

Test 12

Verdict:

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

correct output
1

user output
0

Feedback: Incorrect character on line 1 col 1: expected "1", got "0"

Test 13

Verdict:

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

correct output
1

user output
0

Feedback: Incorrect character on line 1 col 1: expected "1", got "0"