Submission #341727

#TimeUsernameProblemLanguageResultExecution timeMemory
341727ProUGTraffic (IOI10_traffic)C++14
Compilation error
0 ms0 KiB
#include <bits/stdc++.h> using namespace std; vector<int> adj[1000000]; int population_below[100005]; int population[100005]; int highest_traffic[1000005]; int calculate_population (int node, int parent) { int total_population = population[node]; for (auto child : adj[node]) { if (child != parent) { total_population += calculate_population(child, node ); } } population_below[node] = total_population; return total_population; } void dfs (int node, int parent, int overload) { int current_ans = overload; int children_population = 0; for (auto child : adj[node]) { if (child != parent) { children_population += population_below[child]; current_ans = max(current_ans, population_below[child]); } } highest_traffic[node] = current_ans; for (auto child : adj[node]) { if (child != parent) { dfs(child, node, overload + population[node] + children_population - p[child]); } } } int LocateCentre (int n, int p[], int d[], int s[]) { int root = 0; for (int i = 0; i < n; i++) { population[i] = p[i]; } for (int i = 0; i < n-1; i++) { int a, b; a = d[i]; b = s[i]; adj[a].push_back(b); adj[b].push_back(a); } calculate_population(root, -1, s); int lowest_traffic = INT_MAX, lowest_index = 0; for (int i = 0; i < n; i++) { if (highest_traffic[i] < lowest_traffic) { lowest_traffic = highest_traffic[i]; lowest_traffic = i; } } return lowest_index; }

Compilation message (stderr)

traffic.cpp: In function 'void dfs(int, int, int)':
traffic.cpp:36:82: error: 'p' was not declared in this scope
   36 |             dfs(child, node, overload + population[node] + children_population - p[child]);
      |                                                                                  ^
traffic.cpp: In function 'int LocateCentre(int, int*, int*, int*)':
traffic.cpp:56:37: error: too many arguments to function 'int calculate_population(int, int)'
   56 |     calculate_population(root, -1, s);
      |                                     ^
traffic.cpp:9:5: note: declared here
    9 | int calculate_population (int node, int parent) {
      |     ^~~~~~~~~~~~~~~~~~~~