# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
411620 |
2021-05-25T15:52:47 Z |
A_D |
Race (IOI11_race) |
C++14 |
|
1324 ms |
209212 KB |
#include "race.h"
#include <bits/stdc++.h>
#define LL long long
#define ii pair<LL,LL>
#define F first
#define S second
using namespace std;
const int INF=1e18;
const LL NN=2e5+100;
vector<ii> g[NN];
LL dp[NN][111];
LL n,k;
LL ans=INF;
multiset<LL> st;
void dfs(LL u,LL p)
{
dp[u][0]=0;
for(auto x:g[u]){
if(x.F==p)continue;
dfs(x.F,u);
}
for(auto x:g[u]){
if(x.F==p)continue;
for(LL i=0;i<=k;i++){
if(i-x.S>=0)dp[u][i]=min(dp[x.F][i-x.S]+1,dp[u][i]);
}
}
if((g[u].size()==2&&u!=p)||g[u].size()==1)return;
for(LL i=0;i<=k;i++){
st.clear();
st.insert(INF);
for(auto x:g[u]){
if(x.F==p)continue;
if(i-x.S>=0){
st.insert(dp[x.F][i-x.S]);
while(st.size()>2){
st.erase(st.find(*st.rbegin()));
}
}
}
for(auto x:g[u]){
if(x.F==p)continue;
if(i-x.S>=0&&st.find(dp[x.F][i-x.S])!=st.end())st.erase(st.find(dp[x.F][i-x.S]));
LL j=(k-i)-x.S;
if(j>=0){
LL ret=*st.begin();
ret+=dp[x.F][j];
ans=min(ans,ret+2);
}
if(i-x.S>=0){
st.insert(dp[x.F][i-x.S]);
while(st.size()>2){
st.erase(st.find(*st.rbegin()));
}
}
}
}
}
int best_path(int N, int K, int H[][2], int L[])
{
ans=INF;
n=N;
k=K;
for(LL i=0;i<n;i++){
for(LL j=0;j<=k;j++){
dp[i][j]=INF;
}
}
for(LL i=0;i<n-1;i++){
LL u=H[i][0];
LL v=H[i][1];
LL w=L[i];
g[u].push_back({v,w});
g[v].push_back({u,w});
}
dfs(0,0);
for(LL i=0;i<n;i++){
ans=min(ans,dp[i][k]);
}
if(ans==INF)ans=-1;
int ann=ans;
return ann;
}
Compilation message
race.cpp:8:15: warning: overflow in conversion from 'double' to 'int' changes value from '1.0e+18' to '2147483647' [-Woverflow]
8 | const int INF=1e18;
| ^~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
5068 KB |
Output is correct |
2 |
Correct |
4 ms |
5068 KB |
Output is correct |
3 |
Correct |
4 ms |
5068 KB |
Output is correct |
4 |
Correct |
3 ms |
5068 KB |
Output is correct |
5 |
Correct |
3 ms |
5068 KB |
Output is correct |
6 |
Correct |
3 ms |
5068 KB |
Output is correct |
7 |
Correct |
3 ms |
5068 KB |
Output is correct |
8 |
Correct |
3 ms |
5068 KB |
Output is correct |
9 |
Correct |
4 ms |
5068 KB |
Output is correct |
10 |
Correct |
3 ms |
5068 KB |
Output is correct |
11 |
Correct |
3 ms |
5068 KB |
Output is correct |
12 |
Correct |
3 ms |
5068 KB |
Output is correct |
13 |
Correct |
3 ms |
5068 KB |
Output is correct |
14 |
Correct |
4 ms |
5068 KB |
Output is correct |
15 |
Correct |
3 ms |
5068 KB |
Output is correct |
16 |
Correct |
4 ms |
5104 KB |
Output is correct |
17 |
Correct |
4 ms |
5068 KB |
Output is correct |
18 |
Correct |
3 ms |
5068 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
5068 KB |
Output is correct |
2 |
Correct |
4 ms |
5068 KB |
Output is correct |
3 |
Correct |
4 ms |
5068 KB |
Output is correct |
4 |
Correct |
3 ms |
5068 KB |
Output is correct |
5 |
Correct |
3 ms |
5068 KB |
Output is correct |
6 |
Correct |
3 ms |
5068 KB |
Output is correct |
7 |
Correct |
3 ms |
5068 KB |
Output is correct |
8 |
Correct |
3 ms |
5068 KB |
Output is correct |
9 |
Correct |
4 ms |
5068 KB |
Output is correct |
10 |
Correct |
3 ms |
5068 KB |
Output is correct |
11 |
Correct |
3 ms |
5068 KB |
Output is correct |
12 |
Correct |
3 ms |
5068 KB |
Output is correct |
13 |
Correct |
3 ms |
5068 KB |
Output is correct |
14 |
Correct |
4 ms |
5068 KB |
Output is correct |
15 |
Correct |
3 ms |
5068 KB |
Output is correct |
16 |
Correct |
4 ms |
5104 KB |
Output is correct |
17 |
Correct |
4 ms |
5068 KB |
Output is correct |
18 |
Correct |
3 ms |
5068 KB |
Output is correct |
19 |
Correct |
4 ms |
4940 KB |
Output is correct |
20 |
Correct |
4 ms |
5068 KB |
Output is correct |
21 |
Incorrect |
70 ms |
5892 KB |
Output isn't correct |
22 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
5068 KB |
Output is correct |
2 |
Correct |
4 ms |
5068 KB |
Output is correct |
3 |
Correct |
4 ms |
5068 KB |
Output is correct |
4 |
Correct |
3 ms |
5068 KB |
Output is correct |
5 |
Correct |
3 ms |
5068 KB |
Output is correct |
6 |
Correct |
3 ms |
5068 KB |
Output is correct |
7 |
Correct |
3 ms |
5068 KB |
Output is correct |
8 |
Correct |
3 ms |
5068 KB |
Output is correct |
9 |
Correct |
4 ms |
5068 KB |
Output is correct |
10 |
Correct |
3 ms |
5068 KB |
Output is correct |
11 |
Correct |
3 ms |
5068 KB |
Output is correct |
12 |
Correct |
3 ms |
5068 KB |
Output is correct |
13 |
Correct |
3 ms |
5068 KB |
Output is correct |
14 |
Correct |
4 ms |
5068 KB |
Output is correct |
15 |
Correct |
3 ms |
5068 KB |
Output is correct |
16 |
Correct |
4 ms |
5104 KB |
Output is correct |
17 |
Correct |
4 ms |
5068 KB |
Output is correct |
18 |
Correct |
3 ms |
5068 KB |
Output is correct |
19 |
Correct |
909 ms |
98156 KB |
Output is correct |
20 |
Correct |
969 ms |
98256 KB |
Output is correct |
21 |
Correct |
930 ms |
98160 KB |
Output is correct |
22 |
Correct |
1035 ms |
98188 KB |
Output is correct |
23 |
Correct |
861 ms |
98628 KB |
Output is correct |
24 |
Correct |
814 ms |
97756 KB |
Output is correct |
25 |
Correct |
140 ms |
102600 KB |
Output is correct |
26 |
Correct |
128 ms |
107144 KB |
Output is correct |
27 |
Correct |
1116 ms |
190876 KB |
Output is correct |
28 |
Correct |
319 ms |
209212 KB |
Output is correct |
29 |
Correct |
314 ms |
207824 KB |
Output is correct |
30 |
Correct |
1122 ms |
190788 KB |
Output is correct |
31 |
Correct |
1111 ms |
190828 KB |
Output is correct |
32 |
Correct |
1324 ms |
190540 KB |
Output is correct |
33 |
Correct |
326 ms |
192752 KB |
Output is correct |
34 |
Correct |
249 ms |
193016 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
5068 KB |
Output is correct |
2 |
Correct |
4 ms |
5068 KB |
Output is correct |
3 |
Correct |
4 ms |
5068 KB |
Output is correct |
4 |
Correct |
3 ms |
5068 KB |
Output is correct |
5 |
Correct |
3 ms |
5068 KB |
Output is correct |
6 |
Correct |
3 ms |
5068 KB |
Output is correct |
7 |
Correct |
3 ms |
5068 KB |
Output is correct |
8 |
Correct |
3 ms |
5068 KB |
Output is correct |
9 |
Correct |
4 ms |
5068 KB |
Output is correct |
10 |
Correct |
3 ms |
5068 KB |
Output is correct |
11 |
Correct |
3 ms |
5068 KB |
Output is correct |
12 |
Correct |
3 ms |
5068 KB |
Output is correct |
13 |
Correct |
3 ms |
5068 KB |
Output is correct |
14 |
Correct |
4 ms |
5068 KB |
Output is correct |
15 |
Correct |
3 ms |
5068 KB |
Output is correct |
16 |
Correct |
4 ms |
5104 KB |
Output is correct |
17 |
Correct |
4 ms |
5068 KB |
Output is correct |
18 |
Correct |
3 ms |
5068 KB |
Output is correct |
19 |
Correct |
4 ms |
4940 KB |
Output is correct |
20 |
Correct |
4 ms |
5068 KB |
Output is correct |
21 |
Incorrect |
70 ms |
5892 KB |
Output isn't correct |
22 |
Halted |
0 ms |
0 KB |
- |