CSES - Datatähti 2022 alku - Results
Submission details
Task:Tietoverkko
Sender:cowperso
Submission time:2021-10-09 10:00:41 +0300
Language:C++ (C++11)
Status:COMPILE ERROR

Compiler report

input/code.cpp: In function 'int main()':
input/code.cpp:44:73: error: use of 'auto' in lambda parameter declaration only available with -std=c++14 or -std=gnu++14
             find_if(begin(puu[solmu.first]), end(puu[solmu.first]), [i](auto val){return val.first == i; })->second -= 1;
                                                                         ^~~~
input/code.cpp: In lambda function:
input/code.cpp:44:94: error: request for member 'first' in 'val', which is of non-class type 'int'
             find_if(begin(puu[solmu.first]), end(puu[solmu.first]), [i](auto val){return val.first == i; })->second -= 1;
                                                                                              ^~~~~
In file included from /usr/include/c++/7/bits/stl_algobase.h:71:0,
                 from /usr/include/c++/7/bits/char_traits.h:39,
                 from /usr/include/c++/7/ios:40,
                 from /usr/include/c++/7/ostream:38,
                 from /usr/include/c++/7/ios...

Code

#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>
using namespace std;

static vector<vector<pair<uint64_t, uint64_t>>> puu;

static uint64_t hitaammat(uint64_t s, uint64_t e, uint64_t vert) {
    uint64_t summa = 0;
    for (auto seur : puu[s]) {
        if (seur.first == e)
            continue;
        if (seur.second < vert)
            continue;
        summa += hitaammat(seur.first, s, vert) + 1;
    }
    return summa;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    uint64_t n;
    cin >> n;

    puu.reserve(n);

    for (uint64_t i = 0; i < n - 1; ++i) {
        uint64_t a, b, nopeus;
        cin >> a >> b >> nopeus;
        puu[a - 1].push_back({b - 1, nopeus});
        puu[b - 1].push_back({a - 1, nopeus});
    }

    uint64_t summa = 0;
    for (uint64_t i = 0; i < n; ++i) {
        for (auto& solmu : puu[i]) {
            if (i > solmu.first)
                continue;
            summa += (hitaammat(i, solmu.first, solmu.second) + 1) * (hitaammat(solmu.first, i, solmu.second) + 1) * solmu.second;
            solmu.second -= 1;
            find_if(begin(puu[solmu.first]), end(puu[solmu.first]), [i](auto val){return val.first == i; })->second -= 1;
        }
    }

    cout << summa << '\n';
}