CSES - Datatähti 2022 alku - Results
Submission details
Task:Tietoverkko
Sender:Kaapipo
Submission time:2021-10-11 13:01:04 +0300
Language:Python3 (CPython3)
Status:READY
Result:10
Feedback
groupverdictscore
#1ACCEPTED10
#20
#30
Test results
testverdicttimegroup
#1ACCEPTED0.40 s1, 2, 3details
#2--2, 3details
#3--3details

Code

tree = {}
visited = []
speeds = []
def dfs(start, end, smallest):
	visited.append(start)
#	speeds.append(tree[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]:
#		print("speed", speed)
		if neighbor not in visited:
#			candidate = min(candidate, dfs(neighbor, end, speed))
			speeds.append(speed)
			dfs(neighbor, end, speed)
			speeds.pop()
		
	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 = []
		try:	
			dfs(start, end, 1e9)
		except:
			total += min(speeds)
print(total)
	
#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:

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:

input
200000
1 2 613084013
1 3 832364259
2 4 411999902
3 5 989696303
...

correct output
1080549209850010931

user output
(empty)