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

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:

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)