Submission #296365

# Submission time Handle Problem Language Result Execution time Memory
296365 2020-09-10T13:55:09 Z morato Traffic (IOI10_traffic) C++17
Compilation error
0 ms 0 KB
#include <bits/stdc++.h>
using namespace std;

const int maxn = 1e6 + 5;

int p[maxn], h[maxn], tot;

void dfs(int v, int _p = -1) {
  for (int u : adj[v]) if (u != _p) {
    dfs(u, v);
    sub[v] += sub[u] + p[u];
    h[v] = max(h[v], sub[u] + p[u]);
  }
}

int LocateCentre(int N, int *P, int *S, int *D) {
  for (int i = 0; i < N; i++) {
    p[i] = P[i];
    tot += p[i];
  }
  for (int i = 0; i < N; i++) {
    adj[S[i]].push_back(D[i]);
    adj[D[i]].push_back(S[i]);
  }
  dfs(0);
  int ans = h[0];
  for (int i = 1; i < n; i++) {
    h[i] = max(h[i], tot - sub[i] - p[i]);
    ans = min(ans, h[i]);
  }
  return ans;
}

Compilation message

traffic.cpp: In function 'void dfs(int, int)':
traffic.cpp:9:16: error: 'adj' was not declared in this scope
    9 |   for (int u : adj[v]) if (u != _p) {
      |                ^~~
traffic.cpp:11:5: error: 'sub' was not declared in this scope
   11 |     sub[v] += sub[u] + p[u];
      |     ^~~
traffic.cpp: In function 'int LocateCentre(int, int*, int*, int*)':
traffic.cpp:22:5: error: 'adj' was not declared in this scope
   22 |     adj[S[i]].push_back(D[i]);
      |     ^~~
traffic.cpp:27:23: error: 'n' was not declared in this scope
   27 |   for (int i = 1; i < n; i++) {
      |                       ^
traffic.cpp:28:28: error: 'sub' was not declared in this scope
   28 |     h[i] = max(h[i], tot - sub[i] - p[i]);
      |                            ^~~