CSES - Datatähti 2022 alku - Results
Submission details
Task:Tietoverkko (Network)
Sender:jogr
Submission time:2021-10-04 16:40:03
Language:CPython3
Status:READY
Result:0
Feedback
groupverdictscore
#10
#20
#30
Test results
testverdicttimegroup
#10.03 s1, 2, 3details
#2--2, 3details
#3--3details

Code

n=int(input())

total_nconn = n * (n-1)
conn = [dict()] * n

for i in range(0, n-1):
    c1, c2, sp = map(int, input().split())
    c1 -= 1
    c2 -= 1
    conn[c1][c2] = sp
    conn[c2][c1] = sp

s=0

def find_connection(c1, c2):
    while not c2 in conn[c1].keys():
        if c2 in conn[oth].keys():
            conn[c1][c2] = conn[oth][c2]
            conn[c2][c1] = conn[oth][c2]
        for oth in conn[c1].keys():
            find_connection(oth, c2)
    return conn[c1][c2]
    

for c in range(0, n-1):
    for o in range(c, n-1):
        s += find_connection(c, o)
        
print(s)


Test details

Test 1

Group: 1, 2, 3

Verdict:

input
100
1 2 74
1 3 100
2 4 50
3 5 40
...

correct output
88687

user output
247852

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)