CSES - Datatähti 2022 alku - Results
Submission details
Task:Tietoverkko
Sender:tassu
Submission time:2021-10-05 18:55:58 +0300
Language:C++17
Status:COMPILE ERROR

Compiler report

In file included from /usr/include/c++/7/algorithm:62:0,
                 from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:65,
                 from input/code.cpp:1:
/usr/include/c++/7/bits/stl_algo.h: In instantiation of '_ForwardIterator std::search(_ForwardIterator, _ForwardIterator, const _Searcher&) [with _ForwardIterator = int; _Searcher = int]':
input/code.cpp:37:31:   required from here
/usr/include/c++/7/bits/stl_algo.h:4273:24: error: expression cannot be used as a function
     { return __searcher(__first, __last).first; }
              ~~~~~~~~~~^~~~~~~~~~~~~~~~~

Code

#include <bits/stdc++.h>
#include <vector>

#define MAX_SPEED 1000000000

using namespace std;

long speed_total = 0;
vector<pair<int, long>> v[2000];

void search(int s, int e, long speed) {
    if (speed != MAX_SPEED) {
        speed_total += speed;
    }

    for (auto u : v[s]) {
        if (u.first != e) {
            search(u.first, s, min(speed, u.second));
        }
    }
}

int main() {
    int l;
    cin >> l;

    int a, b;
    long x;

    for (int i = 1; i < l; i++) {
        cin >> a >> b >> x;
        v[a - 1].emplace_back(b - 1, x);
        v[b - 1].emplace_back(a - 1, x);
    }

    for (int j = 0; j < l; j++) {
        search(j, j, MAX_SPEED);
    }

    cout << (speed_total / 2) << "\n";

    return 0;
}