Submission #1090124

#TimeUsernameProblemLanguageResultExecution timeMemory
1090124LilPlutonRace (IOI11_race)C++14
0 / 100
6 ms14428 KiB
#include "race.h" #include <bits/stdc++.h> using namespace std; const int sz = 2e5 + 5; int n, k; vector<vector<pair<int, int>>> adj(sz); map<int, int> a[sz]; long long sum[sz], dep[sz], res; void comp(int u, int p, long long c, int h) { a[u][c] = h; sum[u] = c; dep[u] = h; for (auto n : adj[u]) { if (p == n.first) { continue; } comp(n.first, u, c + n.second, h + 1); } } void dfs(int v, int p) { int t = k + 2 * sum[v]; for (auto i : adj[v]) { if (i.first == p) { continue; } if (a[i.first].size() > a[v].size()) { swap(a[i.first], a[v]); } for (auto j : a[i.first]) { if (a[v].find(t - j.first) != a[v].end()) { res = min(res, a[v][t - j.first] + j.second - 2 * dep[v]); } } for (auto j : a[i.first]) { if (a[v].find(j.first) == a[v].end()) { a[v].insert(j); } else { a[v][j.first] = min(a[v][j.first], j.second); } } } } int best_path(int N, int K, int H[][2], int L[]) { if (K == 1) { return 0; } n = N; k = K; for (int i = 0; i < n - 1; ++i) { adj[H[i][0]].push_back({H[i][1], L[i]}); adj[H[i][1]].push_back({H[i][0], L[i]}); } res = INT_MAX; comp(0, -1, 0, 0); dfs(0, -1); return (res == INT_MAX ? -1 : res); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...