Submission #881016

#TimeUsernameProblemLanguageResultExecution timeMemory
881016minhi1Race (IOI11_race)C++14
Compilation error
0 ms0 KiB
#include <bits/stdc++.h> using namespace std; const int N = 1e6 + 6; int n, res = (int)1e9; long long target; int sz[N]; int mp[N]; bool is_removed[N]; bool in_map[N]; vector < int > del; vector < pair < int , int > > adj[N]; int dfs_sz(int u, int p = -1) { sz[u] = 1; for (auto [v, w] : adj[u]) { if (v == p || is_removed[v]) continue; sz[u] += dfs_sz(v, u); } return sz[u]; } int get_cent(int u, int tree_size, int p) { for (auto [v, w] : adj[u]) { if (v == p || is_removed[v]) continue; if (sz[v] * 2 > tree_size) return get_cent(v, tree_size, u); } return u; } void solve(int u, int cent, int p, long long sum, int dist) { if (sum <= target && mp[target - sum] > 0) res = min(res, dist + mp[target - sum]); if (sum == target) res = min(res, dist); for (auto [v, w] : adj[u]) { if (v == p || is_removed[v]) continue; if (sum + w > target) continue; solve(v, cent, u, sum + w, dist + 1); } } void upd(int u, int cent, int p, long long sum, int dist) { if (sum <= target) { int val = mp[sum]; val = (val == 0 ? dist : min(val, dist)); mp[sum] = val; if (!in_map[sum]) { in_map[sum] = true; del.push_back(sum); } } for (auto [v, w] : adj[u]) { if (v == p || is_removed[v]) continue; if (sum + w > target) continue; upd(v, cent, u, sum + w, dist + 1); } } void decomp(int u) { int cent = get_cent(u, dfs_sz(u), -1); for (auto [v, w] : adj[cent]) { if (is_removed[v]) continue; solve(v, cent, cent, w, 1); upd(v, cent, cent, w, 1); } // TODO: refresh for (int sum : del) { mp[sum] = 0; in_map[sum] = 0; } del.clear(); is_removed[cent] = true; for (auto [v, w] : adj[cent]) { if (is_removed[v]) continue; decomp(v); } } int main() { ios::sync_with_stdio(0); cin.tie(0); #ifdef trcute freopen("test.inp", "r", stdin); // freopen("test.out", "w", stdout); #endif cin >> n >> target; for (int i = 1; i < n; ++i) { int u, v, w; cin >> u >> v >> w; ++u; ++v; adj[u].push_back({v, w}); adj[v].push_back({u, w}); } decomp(1); cout << (res == (int)1e9 ? -1 : res); return 0; }

Compilation message (stderr)

race.cpp: In function 'int dfs_sz(int, int)':
race.cpp:17:15: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   17 |     for (auto [v, w] : adj[u]) {
      |               ^
race.cpp: In function 'int get_cent(int, int, int)':
race.cpp:25:15: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   25 |     for (auto [v, w] : adj[u]) {
      |               ^
race.cpp: In function 'void solve(int, int, int, long long int, int)':
race.cpp:37:15: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   37 |     for (auto [v, w] : adj[u]) {
      |               ^
race.cpp: In function 'void upd(int, int, int, long long int, int)':
race.cpp:55:15: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   55 |     for (auto [v, w] : adj[u]) {
      |               ^
race.cpp: In function 'void decomp(int)':
race.cpp:65:15: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   65 |     for (auto [v, w] : adj[cent]) {
      |               ^
race.cpp:80:15: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   80 |     for (auto [v, w] : adj[cent]) {
      |               ^
/usr/bin/ld: /tmp/ccLRmf3L.o: in function `main':
race.cpp:(.text.startup+0x0): multiple definition of `main'; /tmp/ccBGsaWL.o:grader.cpp:(.text.startup+0x0): first defined here
/usr/bin/ld: /tmp/ccBGsaWL.o: in function `main':
grader.cpp:(.text.startup+0x28): undefined reference to `best_path(int, int, int (*) [2], int*)'
collect2: error: ld returned 1 exit status