Submission #748119

# Submission time Handle Problem Language Result Execution time Memory
748119 2023-05-25T12:15:54 Z Prieved1 Race (IOI11_race) C++17
100 / 100
519 ms 148120 KB
#include "race.h"
#include<bits/stdc++.h>
using namespace std;
const int N=1000'010;
vector<pair<int,int>> g[N];
int n, k;
int sz[N], depth[N], dist[N];
map<long long, int> mn[N];
int res;
void getsz(int at, int p, long long sum=0, int d=0) {
  sz[at]=1;
  dist[at]=sum;
  depth[at]=d;
  for(auto to:g[at]) {
    if(to.first==p)continue;
    getsz(to.first, at, sum+to.second, d+1);
    sz[at]+=sz[to.first];
  }
}
void dfs(int at, int p) {
  for(auto [to,tmp]:g[at]) {
    if(to==p)continue;
    dfs(to,at);
    if(mn[to].size()>mn[at].size()) {
      swap(mn[to], mn[at]);
    }
    for(auto [dis, dep]:mn[to]) {
      long long y=k+2*dist[at]-dis;
      if(mn[at].find(y)!=mn[at].end()){
        res=min(res, mn[at][y]+dep-2*depth[at]);
      }
    }
    for(auto [dis, dep]:mn[to]) {
      if(mn[at][dis]==0)mn[at][dis]=dep;
      mn[at][dis]=min(mn[at][dis], dep);
    }
  }
  if(mn[at].find(dist[at]+k)!=mn[at].end()){
    res=min(res, mn[at][dist[at]+k]-depth[at]);
  }
  if(mn[at][dist[at]]!=0)mn[at][dist[at]]=min(mn[at][dist[at]], depth[at]);
  else mn[at][dist[at]]=depth[at];
}
int best_path(int _N, int _K, int H[][2], int L[])
{
  n=_N, k=_K;
  for(int i = 0;i<_N-1;i++) {
    g[H[i][0]].push_back({H[i][1],L[i]});
    g[H[i][1]].push_back({H[i][0],L[i]});
  }
  getsz(0,-1,0,1);
  res=1e9;
  dfs(0,-1);
  if(res==1e9)return -1;
  return res;
}
   
# Verdict Execution time Memory Grader output
1 Correct 32 ms 70732 KB Output is correct
2 Correct 33 ms 70808 KB Output is correct
3 Correct 35 ms 70792 KB Output is correct
4 Correct 33 ms 70752 KB Output is correct
5 Correct 34 ms 70740 KB Output is correct
6 Correct 33 ms 70676 KB Output is correct
7 Correct 32 ms 70732 KB Output is correct
8 Correct 32 ms 70752 KB Output is correct
9 Correct 35 ms 70708 KB Output is correct
10 Correct 32 ms 70808 KB Output is correct
11 Correct 34 ms 70712 KB Output is correct
12 Correct 35 ms 70736 KB Output is correct
13 Correct 35 ms 70684 KB Output is correct
14 Correct 34 ms 70784 KB Output is correct
15 Correct 32 ms 70688 KB Output is correct
16 Correct 31 ms 70740 KB Output is correct
17 Correct 32 ms 70732 KB Output is correct
18 Correct 32 ms 70788 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 32 ms 70732 KB Output is correct
2 Correct 33 ms 70808 KB Output is correct
3 Correct 35 ms 70792 KB Output is correct
4 Correct 33 ms 70752 KB Output is correct
5 Correct 34 ms 70740 KB Output is correct
6 Correct 33 ms 70676 KB Output is correct
7 Correct 32 ms 70732 KB Output is correct
8 Correct 32 ms 70752 KB Output is correct
9 Correct 35 ms 70708 KB Output is correct
10 Correct 32 ms 70808 KB Output is correct
11 Correct 34 ms 70712 KB Output is correct
12 Correct 35 ms 70736 KB Output is correct
13 Correct 35 ms 70684 KB Output is correct
14 Correct 34 ms 70784 KB Output is correct
15 Correct 32 ms 70688 KB Output is correct
16 Correct 31 ms 70740 KB Output is correct
17 Correct 32 ms 70732 KB Output is correct
18 Correct 32 ms 70788 KB Output is correct
19 Correct 33 ms 70792 KB Output is correct
20 Correct 32 ms 70740 KB Output is correct
21 Correct 32 ms 70936 KB Output is correct
22 Correct 34 ms 70936 KB Output is correct
23 Correct 33 ms 70996 KB Output is correct
24 Correct 33 ms 71028 KB Output is correct
25 Correct 36 ms 71128 KB Output is correct
26 Correct 36 ms 71032 KB Output is correct
27 Correct 32 ms 70808 KB Output is correct
28 Correct 32 ms 70984 KB Output is correct
29 Correct 34 ms 71028 KB Output is correct
30 Correct 34 ms 70960 KB Output is correct
31 Correct 33 ms 70996 KB Output is correct
32 Correct 33 ms 70948 KB Output is correct
33 Correct 34 ms 71064 KB Output is correct
34 Correct 33 ms 70972 KB Output is correct
35 Correct 33 ms 70928 KB Output is correct
36 Correct 33 ms 70904 KB Output is correct
37 Correct 33 ms 70888 KB Output is correct
38 Correct 32 ms 70932 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 32 ms 70732 KB Output is correct
2 Correct 33 ms 70808 KB Output is correct
3 Correct 35 ms 70792 KB Output is correct
4 Correct 33 ms 70752 KB Output is correct
5 Correct 34 ms 70740 KB Output is correct
6 Correct 33 ms 70676 KB Output is correct
7 Correct 32 ms 70732 KB Output is correct
8 Correct 32 ms 70752 KB Output is correct
9 Correct 35 ms 70708 KB Output is correct
10 Correct 32 ms 70808 KB Output is correct
11 Correct 34 ms 70712 KB Output is correct
12 Correct 35 ms 70736 KB Output is correct
13 Correct 35 ms 70684 KB Output is correct
14 Correct 34 ms 70784 KB Output is correct
15 Correct 32 ms 70688 KB Output is correct
16 Correct 31 ms 70740 KB Output is correct
17 Correct 32 ms 70732 KB Output is correct
18 Correct 32 ms 70788 KB Output is correct
19 Correct 140 ms 88012 KB Output is correct
20 Correct 135 ms 88064 KB Output is correct
21 Correct 136 ms 87920 KB Output is correct
22 Correct 148 ms 88176 KB Output is correct
23 Correct 192 ms 101032 KB Output is correct
24 Correct 157 ms 94088 KB Output is correct
25 Correct 111 ms 85916 KB Output is correct
26 Correct 79 ms 93528 KB Output is correct
27 Correct 209 ms 95804 KB Output is correct
28 Correct 278 ms 128460 KB Output is correct
29 Correct 292 ms 126908 KB Output is correct
30 Correct 224 ms 95856 KB Output is correct
31 Correct 214 ms 95888 KB Output is correct
32 Correct 264 ms 96020 KB Output is correct
33 Correct 229 ms 94568 KB Output is correct
34 Correct 381 ms 126676 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 32 ms 70732 KB Output is correct
2 Correct 33 ms 70808 KB Output is correct
3 Correct 35 ms 70792 KB Output is correct
4 Correct 33 ms 70752 KB Output is correct
5 Correct 34 ms 70740 KB Output is correct
6 Correct 33 ms 70676 KB Output is correct
7 Correct 32 ms 70732 KB Output is correct
8 Correct 32 ms 70752 KB Output is correct
9 Correct 35 ms 70708 KB Output is correct
10 Correct 32 ms 70808 KB Output is correct
11 Correct 34 ms 70712 KB Output is correct
12 Correct 35 ms 70736 KB Output is correct
13 Correct 35 ms 70684 KB Output is correct
14 Correct 34 ms 70784 KB Output is correct
15 Correct 32 ms 70688 KB Output is correct
16 Correct 31 ms 70740 KB Output is correct
17 Correct 32 ms 70732 KB Output is correct
18 Correct 32 ms 70788 KB Output is correct
19 Correct 33 ms 70792 KB Output is correct
20 Correct 32 ms 70740 KB Output is correct
21 Correct 32 ms 70936 KB Output is correct
22 Correct 34 ms 70936 KB Output is correct
23 Correct 33 ms 70996 KB Output is correct
24 Correct 33 ms 71028 KB Output is correct
25 Correct 36 ms 71128 KB Output is correct
26 Correct 36 ms 71032 KB Output is correct
27 Correct 32 ms 70808 KB Output is correct
28 Correct 32 ms 70984 KB Output is correct
29 Correct 34 ms 71028 KB Output is correct
30 Correct 34 ms 70960 KB Output is correct
31 Correct 33 ms 70996 KB Output is correct
32 Correct 33 ms 70948 KB Output is correct
33 Correct 34 ms 71064 KB Output is correct
34 Correct 33 ms 70972 KB Output is correct
35 Correct 33 ms 70928 KB Output is correct
36 Correct 33 ms 70904 KB Output is correct
37 Correct 33 ms 70888 KB Output is correct
38 Correct 32 ms 70932 KB Output is correct
39 Correct 140 ms 88012 KB Output is correct
40 Correct 135 ms 88064 KB Output is correct
41 Correct 136 ms 87920 KB Output is correct
42 Correct 148 ms 88176 KB Output is correct
43 Correct 192 ms 101032 KB Output is correct
44 Correct 157 ms 94088 KB Output is correct
45 Correct 111 ms 85916 KB Output is correct
46 Correct 79 ms 93528 KB Output is correct
47 Correct 209 ms 95804 KB Output is correct
48 Correct 278 ms 128460 KB Output is correct
49 Correct 292 ms 126908 KB Output is correct
50 Correct 224 ms 95856 KB Output is correct
51 Correct 214 ms 95888 KB Output is correct
52 Correct 264 ms 96020 KB Output is correct
53 Correct 229 ms 94568 KB Output is correct
54 Correct 381 ms 126676 KB Output is correct
55 Correct 46 ms 73548 KB Output is correct
56 Correct 39 ms 72204 KB Output is correct
57 Correct 90 ms 86092 KB Output is correct
58 Correct 78 ms 83264 KB Output is correct
59 Correct 108 ms 99700 KB Output is correct
60 Correct 275 ms 127564 KB Output is correct
61 Correct 247 ms 99156 KB Output is correct
62 Correct 219 ms 95860 KB Output is correct
63 Correct 262 ms 95936 KB Output is correct
64 Correct 509 ms 148120 KB Output is correct
65 Correct 519 ms 147452 KB Output is correct
66 Correct 305 ms 123272 KB Output is correct
67 Correct 189 ms 95840 KB Output is correct
68 Correct 419 ms 114304 KB Output is correct
69 Correct 445 ms 119400 KB Output is correct
70 Correct 394 ms 112720 KB Output is correct