Submission #292657

# Submission time Handle Problem Language Result Execution time Memory
292657 2020-09-07T11:30:18 Z 7_7_7 Traffic (IOI10_traffic) C++17
Compilation error
0 ms 0 KB
#include<bits/stdc++.h>
/// #include "traffic.h"

const int N = 1e6 + 7;

int val[N];
long long ans;
long long total;
long long sub[N];
vector<int> g[N];
long long best = LLONG_MAX;
void dfs(int v, int p){
    long long mx = 0;
    long long curSum = val[v];
    for(auto to: g[v]){
        if(to == p) continue;
        dfs(to, v);
        mx = max(mx, sub[to]);
        curSum += sub[to];
    }
    mx = max(mx, total - curSum);
    if(mx < best){
        best = mx;
        ans = v;
    }
    sub[v] = curSum;
}
int LocateCentre(int n, int p[N], int s[N], int d[N]){
    for(int i = 0; i < n; i ++){
        total += p[i];
        val[i] = p[i];
        if(i < n - 1){
            g[s[i]].push_back(d[i]);
            g[d[i]].push_back(s[i]);
        }
    }
    dfs(0, 0);
    return ans;
}

Compilation message

traffic.cpp:10:1: error: 'vector' does not name a type
   10 | vector<int> g[N];
      | ^~~~~~
traffic.cpp: In function 'void dfs(int, int)':
traffic.cpp:15:18: error: 'g' was not declared in this scope
   15 |     for(auto to: g[v]){
      |                  ^
traffic.cpp:18:14: error: 'max' was not declared in this scope; did you mean 'std::max'?
   18 |         mx = max(mx, sub[to]);
      |              ^~~
      |              std::max
In file included from /usr/include/c++/9/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/9/bits/stdc++.h:65,
                 from traffic.cpp:1:
/usr/include/c++/9/bits/stl_algo.h:3462:5: note: 'std::max' declared here
 3462 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
traffic.cpp:21:10: error: 'max' was not declared in this scope; did you mean 'std::max'?
   21 |     mx = max(mx, total - curSum);
      |          ^~~
      |          std::max
In file included from /usr/include/c++/9/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/9/bits/stdc++.h:65,
                 from traffic.cpp:1:
/usr/include/c++/9/bits/stl_algo.h:3462:5: note: 'std::max' declared here
 3462 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
traffic.cpp: In function 'int LocateCentre(int, int*, int*, int*)':
traffic.cpp:33:13: error: 'g' was not declared in this scope
   33 |             g[s[i]].push_back(d[i]);
      |             ^