| Task: | Airport |
| Sender: | hy2025_002 |
| Submission time: | 2025-10-22 17:39:33 +0300 |
| Language: | Python3 (PyPy3) |
| Status: | READY |
| Result: | TIME LIMIT EXCEEDED |
| test | verdict | time | |
|---|---|---|---|
| #1 | ACCEPTED | 0.04 s | details |
| #2 | ACCEPTED | 0.04 s | details |
| #3 | ACCEPTED | 0.04 s | details |
| #4 | ACCEPTED | 0.04 s | details |
| #5 | ACCEPTED | 0.05 s | details |
| #6 | TIME LIMIT EXCEEDED | -- | details |
| #7 | TIME LIMIT EXCEEDED | -- | details |
| #8 | TIME LIMIT EXCEEDED | -- | details |
| #9 | TIME LIMIT EXCEEDED | -- | details |
| #10 | TIME LIMIT EXCEEDED | -- | details |
| #11 | ACCEPTED | 0.04 s | details |
| #12 | ACCEPTED | 0.04 s | details |
| #13 | ACCEPTED | 0.04 s | details |
Code
class MaximumFlow:
def __init__(self, nodes):
self.nodes = nodes
self.graph = {}
for i in self.nodes:
for j in self.nodes:
self.graph[(i, j)] = 0
def add_edge(self, node_a, node_b, capacity):
self.graph[(node_a, node_b)] += capacity
def add_flow(self, node, sink, flow):
if node in self.seen:
return 0
self.seen.add(node)
if node == sink:
return flow
for next_node in self.nodes:
if self.flow[(node, next_node)] > 0:
new_flow = min(flow, self.flow[(node, next_node)])
inc = self.add_flow(next_node, sink, new_flow)
if inc > 0:
self.flow[(node, next_node)] -= inc
self.flow[(next_node, node)] += inc
return inc
return 0
def construct(self, source, sink):
self.flow = self.graph.copy()
total = 0
while True:
self.seen = set()
add = self.add_flow(source, sink, float("inf"))
if add == 0:
break
total += add
return total
n, m = map(int, input().split())
l = list(map(int, input().split()))
size = 2*n
M = MaximumFlow(range(size))
for i in range(n):
if i == 0 or i == n - 1:
continue
cap = l[i]
if cap == -1:
cap = 10**9
M.add_edge(i, i + n, cap)
for _ in range(m):
a, b = map(int, input().split())
a -= 1
b -= 1
if a == 0:
from_node = 0
else:
from_node = a + n
if b == n - 1:
to_node = n - 1
else:
to_node = b
M.add_edge(from_node, to_node, 10**9)
print(M.construct(0, n - 1))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: TIME LIMIT EXCEEDED
| input |
|---|
| 100 1000 -1 425576195 274150382 1021768... |
| correct output |
|---|
| 6091126630 |
| user output |
|---|
| (empty) |
Test 7
Verdict: TIME LIMIT EXCEEDED
| input |
|---|
| 100 1000 -1 769953265 -1 389517741 2323... |
| correct output |
|---|
| 769953265 |
| user output |
|---|
| (empty) |
Test 8
Verdict: TIME LIMIT EXCEEDED
| input |
|---|
| 100 1000 -1 584988267 763129662 6781413... |
| correct output |
|---|
| 1699511766 |
| user output |
|---|
| (empty) |
Test 9
Verdict: TIME LIMIT EXCEEDED
| input |
|---|
| 100 1000 -1 921671366 121044688 2933366... |
| correct output |
|---|
| 1805833567 |
| user output |
|---|
| (empty) |
Test 10
Verdict: TIME LIMIT EXCEEDED
| input |
|---|
| 100 1000 -1 763842763 612011030 4532521... |
| correct output |
|---|
| 3342235784 |
| user output |
|---|
| (empty) |
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: ACCEPTED
| input |
|---|
| 3 4
-1 1 -1 1 2 1 2 2 3 ... |
| correct output |
|---|
| 1 |
| user output |
|---|
| 1 |
Test 13
Verdict: ACCEPTED
| input |
|---|
| 7 8 -1 1 1 1 1 1 -1 1 2 1 3 2 4 ... |
| correct output |
|---|
| 1 |
| user output |
|---|
| 1 |
