Task: | Tietoverkko |
Sender: | tassu |
Submission time: | 2021-10-05 17:19:02 +0300 |
Language: | Python3 (CPython3) |
Status: | READY |
Result: | 10 |
group | verdict | score |
---|---|---|
#1 | ACCEPTED | 10 |
#2 | TIME LIMIT EXCEEDED | 0 |
#3 | TIME LIMIT EXCEEDED | 0 |
test | verdict | time | group | |
---|---|---|---|---|
#1 | ACCEPTED | 0.10 s | 1, 2, 3 | details |
#2 | TIME LIMIT EXCEEDED | -- | 2, 3 | details |
#3 | RUNTIME ERROR | 0.28 s | 3 | details |
Code
import math l = int(input()) speed_lookup = [[0] * l for i in range(l)] for i in range(l - 1): a, b, x = map(int, input().split(' ')) speed_lookup[a - 1][b - 1] = x speed_lookup[b - 1][a - 1] = x def find_lowest(unvisited, distances): smallest_key, smallest_value = 0, math.inf for key in unvisited: value = distances[key] if value < smallest_value: smallest_key = key return smallest_key def speeds_for(initial): unvisited = list(range(l)) distance = [0 if i == initial else math.inf for i in unvisited] speeds = [math.inf for _ in unvisited] unvisited.remove(initial) current = initial speed_counter = 0 while True: current_distance = distance[current] current_speed = speeds[current] for j in unvisited: speed = speed_lookup[j][current] if speed == 0: continue distance[j] = current_distance + 1 min_speed = min(current_speed, speed) speeds[j] = min_speed speed_counter += min_speed if len(unvisited) == 0: break current = find_lowest(unvisited, distance) unvisited.remove(current) return speed_counter total_speed = 0 for i in range(l): total_speed += speeds_for(i) print(int(total_speed / 2))
Test details
Test 1
Group: 1, 2, 3
Verdict: ACCEPTED
input |
---|
100 1 2 74 1 3 100 2 4 50 3 5 40 ... |
correct output |
---|
88687 |
user output |
---|
88687 |
Test 2
Group: 2, 3
Verdict: TIME LIMIT EXCEEDED
input |
---|
5000 1 2 613084013 1 3 832364259 2 4 411999902 3 5 989696303 ... |
correct output |
---|
1103702320243776 |
user output |
---|
(empty) |
Test 3
Group: 3
Verdict: RUNTIME ERROR
input |
---|
200000 1 2 613084013 1 3 832364259 2 4 411999902 3 5 989696303 ... |
correct output |
---|
1080549209850010931 |
user output |
---|
(empty) |