CSES - Datatähti 2022 alku - Results
Submission details
Task:Tietoverkko (Network)
Sender:hltk
Submission time:2021-10-12 16:32:04
Language:Ruby
Status:READY
Result:100
Feedback
groupverdictscore
#1ACCEPTED10
#2ACCEPTED15
#3ACCEPTED75
Test results
testverdicttimegroup
#1ACCEPTED0.07 s1, 2, 3details
#2ACCEPTED0.08 s2, 3details
#3ACCEPTED0.59 s3details

Code

n,*t=$<.map{|x|x.split.map &:to_i}
t.sort_by!{|x|-x[2]}
p=[-1]*3e5
r=0
t.map{|a,b,c|
  a=p[a]until p[a]<0
  b=p[b]until p[b]<0
  r+=c*p[a]*p[b]
  a,b=b,a if p[a]<p[b]
  p[b]+=p[a]
  p[a]=b
}
p r

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: ACCEPTED

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

correct output
1103702320243776

user output
1103702320243776

Test 3

Group: 3

Verdict: ACCEPTED

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

correct output
1080549209850010931

user output
1080549209850010931