CSES - Datatähti 2024 alku - Results
Submission details
Task:Laskettelukeskus
Sender:Aino
Submission time:2023-10-30 12:39:57 +0200
Language:C++ (C++11)
Status:COMPILE ERROR

Compiler report

input/code.cpp: In function 'int main()':
input/code.cpp:27:26: error: expression cannot be used as a function
   27 |             c=v[c].second();
      |               ~~~~~~~~~~~^~

Code

#include <bits/stdc++.h>

using namespace std;

int main(){
    long long int n, a, b, c, m, k=0;
    vector <pair <long long int, long long int>> v;
    long long int t[n], s[n]={0};
    for (long long int i=0; i<n; i++){
        cin >> a >> b;
        v.push_back ({b-1, a-1});
        s[a-1]++;
        s[b-1]++;
    }
    for (long long int i=0; i<n; i++){
        cin >> a;
        t[i]=a;
    }
    sort (v.begin(), v.end());
    for (long long int i=1; i<n; i++){
        if (s[i]!=1){
            continue;
        }
        c=i;
        m=t[i];
        while (c>0){
            c=v[c].second();
            m=max(m, t[c]);
        }
        k+=m;
    }
    cout << k;
}