Submission #296398

# Submission time Handle Problem Language Result Execution time Memory
296398 2020-09-10T14:18:36 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;

vector<int> adj[maxn];
int p[maxn], h[maxn], sub[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++) {
    adj[S[i]].push_back(D[i]);
    adj[D[i]].push_back(S[i]);
  }
  dfs(0);
  int ans = 0, heavy = h[0];
  for (int i = 1; i < N; i++) {
    h[i] = max(h[i], tot - sub[i] - p[i]);
    if (h[i] < heavy) {
      heavy = h[i];
      ans = i;
    }
  }
  return ans;
}

int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> p[i];
    tot += p[i];
  }
  for (int i = 0; i < n - 1; i++) {
    cin >> s[i] >> d[i];
  }
  cout << LocateCentre(n, p, s, d) << '\n';
  return 0;
}

Compilation message

traffic.cpp: In function 'int main()':
traffic.cpp:42:12: error: 's' was not declared in this scope
   42 |     cin >> s[i] >> d[i];
      |            ^
traffic.cpp:42:20: error: 'd' was not declared in this scope
   42 |     cin >> s[i] >> d[i];
      |                    ^
traffic.cpp:44:30: error: 's' was not declared in this scope
   44 |   cout << LocateCentre(n, p, s, d) << '\n';
      |                              ^
traffic.cpp:44:33: error: 'd' was not declared in this scope
   44 |   cout << LocateCentre(n, p, s, d) << '\n';
      |                                 ^