Submission details
Task:Company Queries II
Sender:jonnymorgan
Submission time:2025-10-23 15:15:44 +0300
Language:Python3 (PyPy3)
Status:READY
Result:
Test results
testverdicttime
#10.07 sdetails
#20.07 sdetails
#30.06 sdetails
#40.06 sdetails
#50.07 sdetails
#60.42 sdetails
#70.42 sdetails
#80.42 sdetails
#90.42 sdetails
#100.42 sdetails
#110.06 sdetails
#120.42 sdetails

Code

from collections import deque


def bfs(s, t, parent, capacity, adj):
    parent[:] = [-1] * len(parent)
    parent[s] = -2
    q = deque([(s, float('inf'))])

    while q:
        cur, flow = q.popleft()
        for nxt in adj[cur]:
            if parent[nxt] == -1 and capacity[cur][nxt]:
                parent[nxt] = cur
                new_flow = min(flow, capacity[cur][nxt])
                if nxt == t:
                    return new_flow
                q.append((nxt, new_flow))
    return 0


n, m = map(int, input().split())
capacity = [[0] * (n + 1) for _ in range(n + 1)]
adj = [[] for _ in range(n + 1)]

for _ in range(m):
    a, b, c = map(int, input().split())
    capacity[a][b] += c
    adj[a].append(b)
    adj[b].append(a)

flow = 0
parent = [-1] * (n + 1)

while True:
    new_flow = bfs(1, n, parent, capacity, adj)
    if new_flow == 0:
        break
    flow += new_flow
    cur = n
    while cur != 1:
        prev = parent[cur]
        capacity[prev][cur] -= new_flow
        capacity[cur][prev] += new_flow
        cur = prev

print(flow)

Test details

Test 1

Verdict:

input
10 10
1 2 3 4 5 6 7 8 9
6 9
8 10
10 3
...

correct output
6
8
3
1
8
...

user output
(empty)

Error:
Traceback (most recent call last):
  File "input/code.py", line 26, in <module>
    a, b, c = map(int, input().split())
ValueError: too many values to unpack (expected 3)

Test 2

Verdict:

input
10 10
1 1 1 1 1 1 1 1 1
1 7
3 4
4 1
...

correct output
1
1
1
1
1
...

user output
(empty)

Error:
Traceback (most recent call last):
  File "input/code.py", line 26, in <module>
    a, b, c = map(int, input().split())
ValueError: too many values to unpack (expected 3)

Test 3

Verdict:

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

correct output
1
1
1
1
1
...

user output
(empty)

Error:
Traceback (most recent call last):
  File "input/code.py", line 26, in <module>
    a, b, c = map(int, input().split())
ValueError: too many values to unpack (expected 3)

Test 4

Verdict:

input
10 10
1 1 3 1 2 2 5 3 9
7 2
7 6
3 9
...

correct output
2
2
3
1
1
...

user output
(empty)

Error:
Traceback (most recent call last):
  File "input/code.py", line 26, in <module>
    a, b, c = map(int, input().split())
ValueError: too many values to unpack (expected 3)

Test 5

Verdict:

input
10 10
1 2 3 2 5 3 2 2 4
6 1
1 3
1 9
...

correct output
1
1
1
2
2
...

user output
(empty)

Error:
Traceback (most recent call last):
  File "input/code.py", line 26, in <module>
    a, b, c = map(int, input().split())
ValueError: too many values to unpack (expected 3)

Test 6

Verdict:

input
200000 200000
1 2 3 4 5 6 7 8 9 10 11 12 13 ...

correct output
74862
8750
16237
72298
58111
...

user output
(empty)

Test 7

Verdict:

input
200000 200000
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...

correct output
1
1
1
1
1
...

user output
(empty)

Test 8

Verdict:

input
200000 200000
1 2 1 2 3 2 1 6 3 1 10 12 13 4...

correct output
1
2
2
2
1
...

user output
(empty)

Test 9

Verdict:

input
200000 200000
1 2 3 4 5 6 7 8 9 10 11 12 13 ...

correct output
2796
633
633
151
2690
...

user output
(empty)

Test 10

Verdict:

input
200000 200000
1 2 3 4 5 6 7 8 9 10 11 12 13 ...

correct output
365
73
103
365
216
...

user output
(empty)

Test 11

Verdict:

input
2 4
1
1 1
1 2
2 1
...

correct output
1
1
1
2

user output
(empty)

Error:
Traceback (most recent call last):
  File "input/code.py", line 26, in <module>
    a, b, c = map(int, input().split())
ValueError: not enough values to unpack (expected 3, got 1)

Test 12

Verdict:

input
200000 200000
1 1 2 3 4 5 6 7 8 9 10 11 12 1...

correct output
27468
6353
27468
6353
6353
...

user output
(empty)