| Task: | Internet connection |
| Sender: | m-x-doctor |
| Submission time: | 2020-09-20 11:15:15 +0300 |
| Language: | Python3 (PyPy3) |
| Status: | READY |
| Result: | TIME LIMIT EXCEEDED |
| test | verdict | time | |
|---|---|---|---|
| #1 | TIME LIMIT EXCEEDED | -- | details |
| #2 | ACCEPTED | 0.05 s | details |
| #3 | ACCEPTED | 0.05 s | details |
| #4 | ACCEPTED | 0.05 s | details |
| #5 | ACCEPTED | 0.05 s | details |
| #6 | ACCEPTED | 0.09 s | details |
| #7 | TIME LIMIT EXCEEDED | -- | details |
| #8 | ACCEPTED | 0.09 s | details |
| #9 | ACCEPTED | 0.09 s | details |
| #10 | ACCEPTED | 0.10 s | details |
| #11 | ACCEPTED | 0.05 s | details |
| #12 | ACCEPTED | 0.05 s | details |
| #13 | ACCEPTED | 0.05 s | details |
| #14 | ACCEPTED | 0.08 s | details |
| #15 | ACCEPTED | 0.05 s | details |
| #16 | ACCEPTED | 0.05 s | details |
| #17 | ACCEPTED | 0.05 s | details |
| #18 | ACCEPTED | 0.06 s | details |
| #19 | ACCEPTED | 0.05 s | details |
| #20 | ACCEPTED | 0.05 s | details |
| #21 | ACCEPTED | 0.05 s | details |
| #22 | ACCEPTED | 0.05 s | details |
Code
"""https://cses.fi/345/task/B"""
from __future__ import print_function
import sys
def eprint(*args, **kwargs):
print(*args, file=sys.stderr, **kwargs)
def get_path_with_dfs(adj_matrix, adj_list, V):
"""DFS uses a stack/list. BFS uses a queue."""
root = 1 # Teemu
target = V # Taina
seen = [] # Stuff you've seen.
to_visit = [root]
path = []
while to_visit:
v = to_visit.pop() # Pop last inserted element.
seen.append(v)
found = False
for neighbor in adj_list[v]:
weight = adj_matrix[v][neighbor]
if (weight < 1) or (neighbor in seen) or (neighbor in path):
continue
# eprint(f"weight from {v} to {neighbor} is {weight}")
found = True
if neighbor == target:
path.append(v)
path.append(target)
return path
to_visit.append(neighbor)
# eprint('to visit', to_visit)
if found:
path.append(v)
# eprint("FOUND: path is ", path)
return None # No path found
def max_rate(adj_matrix, adj_list, V):
total_max_rate = 0
path = get_path_with_dfs(adj_matrix, adj_list, V)
while path:
eprint("path", path)
path_weights = []
for i in range(len(path)-1):
a, b = path[i], path[i+1]
weight = adj_matrix[a][b]
path_weights.append(weight)
eprint('weights', path_weights)
max_rate = min(path_weights)
total_max_rate += max_rate
# Deduct the max_rate from all weights
for i in range(len(path)-1):
a, b = path[i], path[i+1]
adj_matrix[a][b] -= max_rate
adj_matrix[b][a] += max_rate
path = get_path_with_dfs(adj_matrix, adj_list, V)
print(int(total_max_rate))
return
# Read number oof vertices (computers) and edges (connections).
V, E = [int(x) for x in input().split()]
adj_matrix = [[0 for i in range(V + 1)] for i in range(V + 1)]
adj_list = [[] for _ in range(V+1)]
for i in range(E):
a, b, weight = [int(x) for x in input().split()]
adj_matrix[a][b] = weight
adj_list[a].append(b)
adj_list[b].append(a)
max_rate(adj_matrix, adj_list, V)
Test details
Test 1
Verdict: TIME LIMIT EXCEEDED
| input |
|---|
| 10 20 5 6 19 4 5 47 3 5 7 4 9 62 ... |
| correct output |
|---|
| 73 |
| user output |
|---|
| (empty) |
Test 2
Verdict: ACCEPTED
| input |
|---|
| 10 20 2 4 63 7 9 54 6 7 16 2 3 9 ... |
| correct output |
|---|
| 110 |
| user output |
|---|
| 110 |
Error:
path [1, 10] weights [22] path [1, 2, 10] weights [88, 10] path [1, 2, 9, 10] weights [78,...
Test 3
Verdict: ACCEPTED
| input |
|---|
| 10 20 5 6 90 2 3 46 7 8 80 6 7 60 ... |
| correct output |
|---|
| 29 |
| user output |
|---|
| 29 |
Error:
path [1, 2, 6, 10] weights [26, 42, 50] path [1, 6, 10] weights [3, 24]
Test 4
Verdict: ACCEPTED
| input |
|---|
| 10 20 3 4 76 5 7 8 3 8 71 4 7 24 ... |
| correct output |
|---|
| 95 |
| user output |
|---|
| 95 |
Error:
path [1, 2, 7, 10] weights [89, 15, 18] path [1, 2, 3, 8, 9, 10] weights [74, 42, 71, 38,...
Test 5
Verdict: ACCEPTED
| input |
|---|
| 10 20 1 8 22 6 7 40 4 5 20 8 10 77 ... |
| correct output |
|---|
| 156 |
| user output |
|---|
| 156 |
Error:
path [1, 10] weights [81] path [1, 2, 9, 10] weights [53, 82, 9] path [1, 2, 8, 10] weight...
Test 6
Verdict: ACCEPTED
| input |
|---|
| 100 1000 63 85 864540192 22 91 974117435 64 66 953124912 85 88 6080960 ... |
| correct output |
|---|
| 4397669179 |
| user output |
|---|
| 4397669179 |
Error:
path [1, 54, 59, 85, 100] weights [170768914, 255401602, 835234978, 600520102] path [1, 2,...
Test 7
Verdict: TIME LIMIT EXCEEDED
| input |
|---|
| 100 1000 36 93 760720873 12 75 175717522 78 79 340128710 80 83 181753465 ... |
| correct output |
|---|
| 5298558023 |
| user output |
|---|
| (empty) |
Test 8
Verdict: ACCEPTED
| input |
|---|
| 100 1000 20 60 909693891 55 91 570199535 21 41 118646902 37 82 824735480 ... |
| correct output |
|---|
| 5466229311 |
| user output |
|---|
| 5466229311 |
Error:
path [1, 7, 20, 64, 65, 100] weights [862213124, 121065348, 505661517, 975699204, 53643856...
Test 9
Verdict: ACCEPTED
| input |
|---|
| 100 1000 26 44 753330451 62 67 821574279 70 95 219303983 7 44 980013084 ... |
| correct output |
|---|
| 4893925638 |
| user output |
|---|
| 4893925638 |
Error:
path [1, 6, 26, 53, 99, 100] weights [16916041, 205629338, 901388809, 245428508, 472981177...
Test 10
Verdict: ACCEPTED
| input |
|---|
| 100 1000 15 89 501388091 50 71 396801720 15 92 324349822 29 85 184420157 ... |
| correct output |
|---|
| 6956499595 |
| user output |
|---|
| 6956499595 |
Error:
path [1, 84, 97, 100] weights [824921463, 107023333, 477356456] path [1, 84, 85, 86, 97, 1...
Test 11
Verdict: ACCEPTED
| input |
|---|
| 2 1 1 2 1 |
| correct output |
|---|
| 1 |
| user output |
|---|
| 1 |
Error:
path [1, 2] weights [1]
Test 12
Verdict: ACCEPTED
| input |
|---|
| 2 1 2 1 1 |
| correct output |
|---|
| 0 |
| user output |
|---|
| 0 |
Test 13
Verdict: ACCEPTED
| input |
|---|
| 2 2 1 2 1 2 1 1 |
| correct output |
|---|
| 1 |
| user output |
|---|
| 1 |
Error:
path [1, 2] weights [1]
Test 14
Verdict: ACCEPTED
| input |
|---|
| 100 1000 1 2 539540023 2 3 244306651 3 4 253259012 3 5 630461598 ... |
| correct output |
|---|
| 0 |
| user output |
|---|
| 0 |
Test 15
Verdict: ACCEPTED
| input |
|---|
| 4 5 1 2 2 1 3 5 2 4 3 3 2 2 ... |
| correct output |
|---|
| 4 |
| user output |
|---|
| 4 |
Error:
path [1, 3, 4] weights [5, 1] path [1, 3, 2, 4] weights [4, 2, 3] path [1, 2, 4] weights [...
Test 16
Verdict: ACCEPTED
| input |
|---|
| 2 0 |
| correct output |
|---|
| 0 |
| user output |
|---|
| 0 |
Test 17
Verdict: ACCEPTED
| input |
|---|
| 100 0 |
| correct output |
|---|
| 0 |
| user output |
|---|
| 0 |
Test 18
Verdict: ACCEPTED
| input |
|---|
| 100 196 1 2 1000000000 2 100 1000000000 1 3 1000000000 3 100 1000000000 ... |
| correct output |
|---|
| 98000000000 |
| user output |
|---|
| 98000000000 |
Error:
path [1, 99, 100] weights [1000000000, 1000000000] path [1, 98, 100] weights [1000000000,...
Test 19
Verdict: ACCEPTED
| input |
|---|
| 100 99 1 2 1000000000 2 3 1000000000 3 4 1000000000 4 5 1000000000 ... |
| correct output |
|---|
| 1000000000 |
| user output |
|---|
| 1000000000 |
Error:
path [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 2...
Test 20
Verdict: ACCEPTED
| input |
|---|
| 2 2 2 1 1 1 2 1 |
| correct output |
|---|
| 1 |
| user output |
|---|
| 1 |
Error:
path [1, 2] weights [1]
Test 21
Verdict: ACCEPTED
| input |
|---|
| 4 6 1 2 1000000000 1 3 1000000000 2 3 1 2 4 1000000000 ... |
| correct output |
|---|
| 2000000000 |
| user output |
|---|
| 2000000000 |
Error:
path [1, 3, 4] weights [1000000000, 1000000000] path [1, 2, 4] weights [1000000000, 100000...
Test 22
Verdict: ACCEPTED
| input |
|---|
| 4 6 1 2 1000000000 1 3 1000000000 2 4 1000000000 2 3 1 ... |
| correct output |
|---|
| 2000000000 |
| user output |
|---|
| 2000000000 |
Error:
path [1, 3, 4] weights [1000000000, 1000000000] path [1, 2, 4] weights [1000000000, 100000...
