Submission #957803

#TimeUsernameProblemLanguageResultExecution timeMemory
957803Trisanu_DasRace (IOI11_race)C++17
Compilation error
0 ms0 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define pb push_back #define ff first #define sf second vector<pair<ll, ll> > adj[200005]; map<ll, ll> sum_to_dist[200005]; ll dist[maxn], sum[maxn]; int N, K; ll ans; void dfs(int u, int p, ll s, int d) { sum_to_dist[u][s] = d; sum[u] = s; dist[u] = d; for (auto v : adj[u]) if (p != v.ff) dfs(v.ff, u, s + v.ss, d + 1); } void merge_dfs(int u, int p) { ll target = K + 2 * sum[u]; for (auto v : adj[u]) { if (v.ff == p) continue; merge_dfs(v.ff, u); if (sum_to_dist[v.ff].size() > sum_to_dist[u].size()) swap(sum_to_dist[v.ff], sum_to_dist[u]); for (auto p : sum_to_dist[v.ff]) { if (sum_to_dist[u].find(target - p.ff) != sum_to_dist[u].end()) { ans = min(ans, sum_to_dist[u][target - p.ff] + p.ss - 2 * dist[u]); for (auto p : sum_to_dist[v.ff]) { if (sum_to_dist[u].find(p.ff) == sum_to_dist[u].end()) sum_to_dist[u].insert(p); else info[u][p.ff] = min(sum_to_dist[u][p.ff], p.ss); } } } int best_path(int n, int k, int h[][2], int l[]) { if (k == 1) return 0; N = n; K = k; ans = INT_MAX; for (int i = 0; i < n - 1; i++) { int u = h[i][0], v = h[i][1]; adj[u].pb(pii(v, l[i])); adj[v].pb(pii(u, l[i])); } dfs(0, -1, 0, 0); merge_dfs(0, -1); return ans == INT_MAX ? -1 : ans; }

Compilation message (stderr)

race.cpp:10:9: error: 'maxn' was not declared in this scope
   10 | ll dist[maxn], sum[maxn];
      |         ^~~~
race.cpp:10:20: error: 'maxn' was not declared in this scope
   10 | ll dist[maxn], sum[maxn];
      |                    ^~~~
race.cpp: In function 'void dfs(int, int, ll, int)':
race.cpp:16:2: error: 'sum' was not declared in this scope
   16 |  sum[u] = s;
      |  ^~~
race.cpp:17:2: error: 'dist' was not declared in this scope
   17 |  dist[u] = d;
      |  ^~~~
race.cpp:18:58: error: 'struct std::pair<long long int, long long int>' has no member named 'ss'
   18 |  for (auto v : adj[u]) if (p != v.ff) dfs(v.ff, u, s + v.ss, d + 1);
      |                                                          ^~
race.cpp: In function 'void merge_dfs(int, int)':
race.cpp:22:22: error: 'sum' was not declared in this scope
   22 |  ll target = K + 2 * sum[u];
      |                      ^~~
race.cpp:29:54: error: 'struct std::pair<const long long int, long long int>' has no member named 'ss'
   29 |     ans = min(ans, sum_to_dist[u][target - p.ff] + p.ss - 2 * dist[u]);
      |                                                      ^~
race.cpp:29:63: error: 'dist' was not declared in this scope
   29 |     ans = min(ans, sum_to_dist[u][target - p.ff] + p.ss - 2 * dist[u]);
      |                                                               ^~~~
race.cpp:32:9: error: 'info' was not declared in this scope
   32 |    else info[u][p.ff] = min(sum_to_dist[u][p.ff], p.ss);
      |         ^~~~
race.cpp:32:53: error: 'struct std::pair<const long long int, long long int>' has no member named 'ss'
   32 |    else info[u][p.ff] = min(sum_to_dist[u][p.ff], p.ss);
      |                                                     ^~
race.cpp:37:50: error: a function-definition is not allowed here before '{' token
   37 | int best_path(int n, int k, int h[][2], int l[]) {
      |                                                  ^
race.cpp:48:1: error: expected '}' at end of input
   48 | }
      | ^
race.cpp:23:24: note: to match this '{'
   23 |  for (auto v : adj[u]) {
      |                        ^
race.cpp:48:1: error: expected '}' at end of input
   48 | }
      | ^
race.cpp:21:30: note: to match this '{'
   21 | void merge_dfs(int u, int p) {
      |                              ^