Task: | Tietoverkko |
Sender: | Kaapipo |
Submission time: | 2021-10-11 13:26:42 +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.42 s | 1, 2, 3 | details |
#2 | TIME LIMIT EXCEEDED | -- | 2, 3 | details |
#3 | TIME LIMIT EXCEEDED | -- | 3 | details |
Code
tree = {} visited = [] speeds = 1e9 def dfs(start, end, smallest): global speeds # print(speeds) visited.append(start) if start == end: # print("found", start, smallest) raise Exception("Done") # return smallest # if all(map(lambda x: x[0] in visited, tree[start])): # visited.pop() # print("not found at", start) # return smallest # print("now at", start, "going to", end) candidate = smallest for neighbor, speed in tree[start]: if neighbor not in visited: # speeds.append(speed) old_speed = speeds speeds = min(speeds, speed) dfs(neighbor, end, speed) # speeds.pop() speeds = old_speed return candidate n = int(input()) for _ in range(n - 1): a, b, x = map(int, input().split()) if a not in tree: tree[a] = [] tree[a].append((b, x)) if b not in tree: tree[b] = [] tree[b].append((a, x)) total = 0 for start in range(1, n + 1): for end in range(start + 1, n + 1): # print(start, "to", end) visited = [] speeds = 1e9 try: dfs(start, end, 1e9) except: # print(speeds) total += speeds print(total) #try: # dfs(2, 4, 1e9) #except: # print(speeds) #print(tree)
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: TIME LIMIT EXCEEDED
input |
---|
200000 1 2 613084013 1 3 832364259 2 4 411999902 3 5 989696303 ... |
correct output |
---|
1080549209850010931 |
user output |
---|
(empty) |