Submission details
Task:Airport
Sender:aalto25h_004
Submission time:2025-10-22 19:49:45 +0300
Language:Python3 (PyPy3)
Status:READY
Result:
Test results
testverdicttime
#1ACCEPTED0.05 sdetails
#2ACCEPTED0.05 sdetails
#3ACCEPTED0.05 sdetails
#4ACCEPTED0.05 sdetails
#5ACCEPTED0.05 sdetails
#6--details
#7ACCEPTED0.27 sdetails
#8ACCEPTED0.40 sdetails
#9ACCEPTED0.29 sdetails
#10ACCEPTED0.55 sdetails
#11ACCEPTED0.05 sdetails
#120.05 sdetails
#130.05 sdetails

Code

from collections import defaultdict


class FordFulkerson:
    def __init__(self, n):
        self.n = n
        self.graph = defaultdict(list)  # adjacency list of edges

    def add_edge(self, u, v, cap):
        # Forward edge: capacity cap, backward edge: capacity 0
        if cap == -1:
            cap = 100000000000
        self.graph[u].append([v, cap, len(self.graph[v])])
        self.graph[v].append([u, 0, len(self.graph[u]) - 1])

    def _dfs(self, u, t, flow, visited):
        if u == t:
            return flow
        visited[u] = True
        for i, (v, cap, rev) in enumerate(self.graph[u]):
            if not visited[v] and cap > 0:
                curr_flow = min(flow, cap)
                temp_flow = self._dfs(v, t, curr_flow, visited)
                if temp_flow > 0:
                    # Update residual capacities
                    self.graph[u][i][1] -= temp_flow
                    self.graph[v][rev][1] += temp_flow
                    return temp_flow
        return 0

    def max_flow(self, s, t):
        total = 0
        while True:
            visited = [False] * self.n
            flow = self._dfs(s, t, float("inf"), visited)
            if flow == 0:
                break
            total += flow
        return total


# Example usage:

n, m = map(int, input().split())
checkpoints = list(map(int, input().split()))
ff = FordFulkerson(n)

for _ in range(m):
    x, b = map(int, input().split())
    # Convert to zero-based indexing if needed
    if x == 1:
        ff.add_edge(x - 1, b - 1, checkpoints[b - 1])
    elif b == n:
        ff.add_edge(x - 1, b - 1, checkpoints[x - 1])
    else:
        ff.add_edge(x - 1, b - 1, checkpoints[b - 1])


s, t = 0, n - 1  # source and sink
print(ff.max_flow(s, t))

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:

input
100 1000
-1 425576195 274150382 1021768...

correct output
6091126630

user output
(empty)

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

Feedback: Incorrect character on line 1 col 1: expected "1", got "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

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