CSES - Datatähti 2022 alku - Results
Submission details
Task:Tietoverkko
Sender:Totska
Submission time:2021-10-12 10:08:46 +0300
Language:C++17
Status:COMPILE ERROR

Compiler report

input/code.cpp:13:22: error: expected initializer before 'll'
 typedef long long ll ll;
                      ^~
input/code.cpp:17:28: error: 'll' was not declared in this scope
 bool sortcol( const vector<ll>& v1,
                            ^~
input/code.cpp:17:28: note: suggested alternative: 'kill'
 bool sortcol( const vector<ll>& v1,
                            ^~
                            kill
input/code.cpp:17:30: error: template argument 1 is invalid
 bool sortcol( const vector<ll>& v1,
                              ^
input/code.cpp:17:30: error: template argument 2 is invalid
input/code.cpp:18:29: error: 'll' was not declared in this scope
                const vector<ll>& v2 ) {
                             ^~
input/code.cpp:18:31: error: template argument 1 is invalid
                const vector<ll>& v2 ) {
                               ^
input/code.cpp:18:31: error: template argument 2 is invalid
input/code.cpp: In function 'bool sortcol(const int&, const int&)':...

Code

/******************************************************************************

                              Online C++ Compiler.
               Code, Compile, Run and Debug C++ program online.
Write your code in this editor and press "Run" button to compile and execute it.

*******************************************************************************/

#include <iostream>
#include <bits/stdc++.h>
using namespace std;

typedef long long ll ll;



bool sortcol( const vector<ll>& v1,
               const vector<ll>& v2 ) {
 return v1[2] > v2[2];
}

ll id(ll x, vector<ll> edustajat){
    while(x != edustajat[x]) x = edustajat[x];

    return x;
}



ll main()
{
    ll n, u, v, w;

    cin >> n;

    vector<vector<ll>> edges;

    vector<ll> edustajat;
    vector<ll> koot;

    edustajat.resize(n+1);
    koot.resize(n+1);

    for (ll i = 0; i < n+1; i++) {
        edustajat[i] = i;
        koot[i] = 1;
    }

    for (ll i = 0; i < n-1; i++) {
        cin >> u >> v >> w;

        vector<ll> e;

        e.push_back(u);
        e.push_back(v);
        e.push_back(w);

        edges.push_back(e);
    }


    sort(edges.begin(), edges.end(), sortcol);

    ll ans = 0;
    ll a, b;

    for (auto x: edges) {
        a = id(x[0], edustajat);
        b = id(x[1], edustajat);

        ans += x[2] * koot[a] * koot[b];

        if (koot[a] > koot[b]){
            swap(a, b);
        }

        edustajat[a] = b;
        koot[b] += koot[a];
    }

    cout << ans << endl;
}