CSES - Datatähti 2022 alku - Results
Submission details
Task:Tietoverkko (Network)
Sender:Anttono
Submission time:2021-10-06 19:24:15
Language:C++11
Status:READY
Result:25
Feedback
groupverdictscore
#1ACCEPTED10
#2ACCEPTED15
#30
Test results
testverdicttimegroup
#1ACCEPTED0.01 s1, 2, 3details
#2ACCEPTED0.11 s2, 3details
#3--3details

Code

#include <bits/stdc++.h>

using namespace std;

typedef long long int ll;

#define N 200001

int n;
ll r;
set<int> v[N];
int c[N];
set<pair<ll,pair<int,int>>> s;

void nodecount(int a, int e)
{
    c[a] = 1;
    for(auto u : v[a])
    {
        if(u == e) continue;
        nodecount(u, a);
        c[a] += c[u];
    }
}

int main()
{
    cin>>n;
    int a,b;
    ll x;
    for(int i=1;i<n;i++)
    {
        cin>>a>>b>>x;
        v[a].insert(b);
        v[b].insert(a);
        s.insert(make_pair(x,make_pair(a,b)));
    }
    for(auto p : s)
    {
        int a = p.second.first;
        int b = p.second.second;
        ll x = p.first;
        v[a].erase(b);
        v[b].erase(a);
        nodecount(a, 0);
        nodecount(b, 0);
        r += x * c[a] * c[b];
    }
    cout<<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:

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

correct output
1080549209850010931

user output
(empty)