# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1112049 |
2024-11-13T15:03:16 Z |
FucKanh |
Race (IOI11_race) |
C++14 |
|
5 ms |
16720 KB |
#include "race.h"
#include <bits/stdc++.h>
#define pii pair<int,int>
using namespace std;
const int maxn = 2e5 + 2;
int f[(int)1e6 + 2];
int sz[maxn],h[maxn],k;
vector<pii> a[maxn];
int ans = LLONG_MAX;
map<int,int> mp[maxn];
void dfs(int u, int w, int pa) {
for (pii tmp : a[u]) {
int wv,v; tie(v,wv) = tmp;
if (v==pa) continue;
h[v] = h[u] + 1;
dfs(v,w+wv,u);
int t = mp[v][w+wv];
mp[v][w+wv] = (t == 0) ? h[v] : min(t,h[v]);
if (mp[u].size() < mp[v].size()) swap(mp[u],mp[v]);
for (pii val : mp[v]) {
if (val.second==0) continue;
if (val.first - w < k && mp[u][k-val.first+w] != 0) {
ans = min(ans, mp[u][k-val.first+w] - h[u] + val.second - h[u]);
}
}
mp[u].insert(mp[v].begin(),mp[v].end());
if (mp[u][w + k] != 0) {
ans = min(ans, mp[u][w+k]-h[u]);
}
}
}
int best_path(int _n, int _k, int _h[][2], int _L[])
{
k = _k;
for (int i = 0; i < _n - 1; i++){
int x = _h[i][0], y= _h[i][1];
int w = _L[i];
a[x].push_back({y,w});
a[y].push_back({x,w});
}
h[0] = 1;
dfs(0,0,-1);
return ans == LLONG_MAX ? -1 : ans;
}
Compilation message
race.cpp:12:11: warning: overflow in conversion from 'long long int' to 'int' changes value from '9223372036854775807' to '-1' [-Woverflow]
12 | int ans = LLONG_MAX;
| ^~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
5 ms |
16720 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
5 ms |
16720 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
5 ms |
16720 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
5 ms |
16720 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |