Submission #955222

# Submission time Handle Problem Language Result Execution time Memory
955222 2024-03-29T18:47:36 Z Vanilla Race (IOI11_race) C++17
100 / 100
436 ms 83540 KB
#include <bits/stdc++.h>
#include "race.h"
using namespace std;
const int maxn=2e5+2;
vector<pair<int,int>>ad[maxn];
map<int,int>mp[maxn];
int rs=1e9;
void dfs(int u,int p,int k,int d,int h) {
  mp[u][d]=h;
  for(auto[v,c]:ad[u]) {
    if(v==p)continue;
    dfs(v,u,k,d+c,h+1);
    if(mp[v].size()>mp[u].size())swap(mp[u],mp[v]);
    for(auto[cost,node]:mp[v]){
      int rem=k+2*d-cost;
      if (mp[u].count(rem)){
        rs=min(rs,mp[u][rem]+node-2*h);
      }
    }
    for(auto[cost,node]:mp[v]){
      if(!mp[u].count(cost))mp[u][cost]=node;
      mp[u][cost]=min(mp[u][cost],node);
    }
  }
}
int best_path(int n,int k,int h[][2],int l[]){
  for(int i=0;i<n-1;i++){
    ad[h[i][0]].push_back({h[i][1],l[i]});
    ad[h[i][1]].push_back({h[i][0],l[i]});
  }
  dfs(0,-1,k,0,0);
  return rs==(int)1e9?-1:rs;
}

# Verdict Execution time Memory Grader output
1 Correct 4 ms 18012 KB Output is correct
2 Correct 4 ms 18012 KB Output is correct
3 Correct 4 ms 18012 KB Output is correct
4 Correct 4 ms 18012 KB Output is correct
5 Correct 4 ms 18012 KB Output is correct
6 Correct 4 ms 18012 KB Output is correct
7 Correct 4 ms 18012 KB Output is correct
8 Correct 4 ms 18012 KB Output is correct
9 Correct 4 ms 18012 KB Output is correct
10 Correct 4 ms 18012 KB Output is correct
11 Correct 4 ms 18012 KB Output is correct
12 Correct 5 ms 18012 KB Output is correct
13 Correct 5 ms 18196 KB Output is correct
14 Correct 4 ms 18012 KB Output is correct
15 Correct 4 ms 18012 KB Output is correct
16 Correct 5 ms 18012 KB Output is correct
17 Correct 4 ms 18012 KB Output is correct
18 Correct 4 ms 18012 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 18012 KB Output is correct
2 Correct 4 ms 18012 KB Output is correct
3 Correct 4 ms 18012 KB Output is correct
4 Correct 4 ms 18012 KB Output is correct
5 Correct 4 ms 18012 KB Output is correct
6 Correct 4 ms 18012 KB Output is correct
7 Correct 4 ms 18012 KB Output is correct
8 Correct 4 ms 18012 KB Output is correct
9 Correct 4 ms 18012 KB Output is correct
10 Correct 4 ms 18012 KB Output is correct
11 Correct 4 ms 18012 KB Output is correct
12 Correct 5 ms 18012 KB Output is correct
13 Correct 5 ms 18196 KB Output is correct
14 Correct 4 ms 18012 KB Output is correct
15 Correct 4 ms 18012 KB Output is correct
16 Correct 5 ms 18012 KB Output is correct
17 Correct 4 ms 18012 KB Output is correct
18 Correct 4 ms 18012 KB Output is correct
19 Correct 5 ms 18012 KB Output is correct
20 Correct 4 ms 18012 KB Output is correct
21 Correct 5 ms 18296 KB Output is correct
22 Correct 5 ms 18268 KB Output is correct
23 Correct 5 ms 18268 KB Output is correct
24 Correct 5 ms 18400 KB Output is correct
25 Correct 5 ms 18268 KB Output is correct
26 Correct 5 ms 18268 KB Output is correct
27 Correct 4 ms 18268 KB Output is correct
28 Correct 5 ms 18268 KB Output is correct
29 Correct 6 ms 18268 KB Output is correct
30 Correct 5 ms 18268 KB Output is correct
31 Correct 5 ms 18268 KB Output is correct
32 Correct 5 ms 18156 KB Output is correct
33 Correct 5 ms 18268 KB Output is correct
34 Correct 5 ms 18268 KB Output is correct
35 Correct 5 ms 18268 KB Output is correct
36 Correct 5 ms 18268 KB Output is correct
37 Correct 5 ms 18268 KB Output is correct
38 Correct 5 ms 18268 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 18012 KB Output is correct
2 Correct 4 ms 18012 KB Output is correct
3 Correct 4 ms 18012 KB Output is correct
4 Correct 4 ms 18012 KB Output is correct
5 Correct 4 ms 18012 KB Output is correct
6 Correct 4 ms 18012 KB Output is correct
7 Correct 4 ms 18012 KB Output is correct
8 Correct 4 ms 18012 KB Output is correct
9 Correct 4 ms 18012 KB Output is correct
10 Correct 4 ms 18012 KB Output is correct
11 Correct 4 ms 18012 KB Output is correct
12 Correct 5 ms 18012 KB Output is correct
13 Correct 5 ms 18196 KB Output is correct
14 Correct 4 ms 18012 KB Output is correct
15 Correct 4 ms 18012 KB Output is correct
16 Correct 5 ms 18012 KB Output is correct
17 Correct 4 ms 18012 KB Output is correct
18 Correct 4 ms 18012 KB Output is correct
19 Correct 90 ms 35624 KB Output is correct
20 Correct 90 ms 35668 KB Output is correct
21 Correct 87 ms 35428 KB Output is correct
22 Correct 87 ms 35160 KB Output is correct
23 Correct 137 ms 44888 KB Output is correct
24 Correct 103 ms 37712 KB Output is correct
25 Correct 75 ms 36960 KB Output is correct
26 Correct 50 ms 43844 KB Output is correct
27 Correct 144 ms 42324 KB Output is correct
28 Correct 241 ms 76628 KB Output is correct
29 Correct 244 ms 74836 KB Output is correct
30 Correct 158 ms 42292 KB Output is correct
31 Correct 138 ms 42064 KB Output is correct
32 Correct 183 ms 42336 KB Output is correct
33 Correct 184 ms 45908 KB Output is correct
34 Correct 318 ms 69704 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 18012 KB Output is correct
2 Correct 4 ms 18012 KB Output is correct
3 Correct 4 ms 18012 KB Output is correct
4 Correct 4 ms 18012 KB Output is correct
5 Correct 4 ms 18012 KB Output is correct
6 Correct 4 ms 18012 KB Output is correct
7 Correct 4 ms 18012 KB Output is correct
8 Correct 4 ms 18012 KB Output is correct
9 Correct 4 ms 18012 KB Output is correct
10 Correct 4 ms 18012 KB Output is correct
11 Correct 4 ms 18012 KB Output is correct
12 Correct 5 ms 18012 KB Output is correct
13 Correct 5 ms 18196 KB Output is correct
14 Correct 4 ms 18012 KB Output is correct
15 Correct 4 ms 18012 KB Output is correct
16 Correct 5 ms 18012 KB Output is correct
17 Correct 4 ms 18012 KB Output is correct
18 Correct 4 ms 18012 KB Output is correct
19 Correct 5 ms 18012 KB Output is correct
20 Correct 4 ms 18012 KB Output is correct
21 Correct 5 ms 18296 KB Output is correct
22 Correct 5 ms 18268 KB Output is correct
23 Correct 5 ms 18268 KB Output is correct
24 Correct 5 ms 18400 KB Output is correct
25 Correct 5 ms 18268 KB Output is correct
26 Correct 5 ms 18268 KB Output is correct
27 Correct 4 ms 18268 KB Output is correct
28 Correct 5 ms 18268 KB Output is correct
29 Correct 6 ms 18268 KB Output is correct
30 Correct 5 ms 18268 KB Output is correct
31 Correct 5 ms 18268 KB Output is correct
32 Correct 5 ms 18156 KB Output is correct
33 Correct 5 ms 18268 KB Output is correct
34 Correct 5 ms 18268 KB Output is correct
35 Correct 5 ms 18268 KB Output is correct
36 Correct 5 ms 18268 KB Output is correct
37 Correct 5 ms 18268 KB Output is correct
38 Correct 5 ms 18268 KB Output is correct
39 Correct 90 ms 35624 KB Output is correct
40 Correct 90 ms 35668 KB Output is correct
41 Correct 87 ms 35428 KB Output is correct
42 Correct 87 ms 35160 KB Output is correct
43 Correct 137 ms 44888 KB Output is correct
44 Correct 103 ms 37712 KB Output is correct
45 Correct 75 ms 36960 KB Output is correct
46 Correct 50 ms 43844 KB Output is correct
47 Correct 144 ms 42324 KB Output is correct
48 Correct 241 ms 76628 KB Output is correct
49 Correct 244 ms 74836 KB Output is correct
50 Correct 158 ms 42292 KB Output is correct
51 Correct 138 ms 42064 KB Output is correct
52 Correct 183 ms 42336 KB Output is correct
53 Correct 184 ms 45908 KB Output is correct
54 Correct 318 ms 69704 KB Output is correct
55 Correct 17 ms 20316 KB Output is correct
56 Correct 9 ms 19288 KB Output is correct
57 Correct 52 ms 33620 KB Output is correct
58 Correct 45 ms 29016 KB Output is correct
59 Correct 84 ms 48468 KB Output is correct
60 Correct 231 ms 75344 KB Output is correct
61 Correct 175 ms 44788 KB Output is correct
62 Correct 139 ms 42068 KB Output is correct
63 Correct 210 ms 42112 KB Output is correct
64 Correct 436 ms 83540 KB Output is correct
65 Correct 412 ms 81488 KB Output is correct
66 Correct 260 ms 71484 KB Output is correct
67 Correct 126 ms 37824 KB Output is correct
68 Correct 314 ms 54620 KB Output is correct
69 Correct 396 ms 58376 KB Output is correct
70 Correct 284 ms 53040 KB Output is correct