Submission #1090125

#TimeUsernameProblemLanguageResultExecution timeMemory
1090125LilPlutonRace (IOI11_race)C++14
0 / 100
7 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; res = INT_MAX; for (int i = 0; i < n - 1; i++) { int u = H[i][0]; int v = H[i][1]; adj[u].push_back(pair<int,int> (v, L[i])); adj[v].push_back(pair<int,int> (u, L[i])); } 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...