# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1047961 |
2024-08-07T18:53:12 Z |
manhlinh1501 |
Race (IOI11_race) |
C++17 |
|
107 ms |
262144 KB |
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
using pii = pair<int, int>;
const int MAXN = 2e5 + 5;
const int oo32 = 2e9;
vector<pii> adj[MAXN];
map<int, int> res[MAXN];
int ans = oo32;
void DFS(int u, const int N, const int K, i64 c = 0, int depth = 0, int p = -1) {
res[u][c] = depth;
for(auto [v, w] : adj[u]) {
if(v == p) continue;
DFS(v, c + w, depth + 1, u);
if(res[u].size() < res[v].size()) swap(res[u], res[v]);
for(auto [x, y] : res[v]) {
if(res[u].find(c + K - (x - c)) != res[u].end())
ans = min(ans, y + res[u][c + K - (x - c)] - 2 * depth);
}
for(auto [x, y] : res[v]) {
if(res[u].find(x) != res[u].end())
res[u][x] = min(res[u][x], y);
else res[u][x] = y;
}
}
}
int best_path(int N, int K, int H[][2], int L[]) {
for(int i = 0; i < N; i++) {
int u = H[i][0];
int v = H[i][1];
int w = L[i];
adj[u].emplace_back(v, w);
adj[v].emplace_back(u, w);
}
DFS(0, N, K);
return (ans > N ? -1 : ans);
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
107 ms |
262144 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
107 ms |
262144 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
107 ms |
262144 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
107 ms |
262144 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |