Submission #700208

# Submission time Handle Problem Language Result Execution time Memory
700208 2023-02-18T20:44:51 Z mnbvcxz123 Race (IOI11_race) C++17
100 / 100
942 ms 41872 KB
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using ar=array<ll,2>;
ll n,k,res=1e7;
vector<ar>g[200000];
ll sz[200000];
bool used[200000];
map<ll,ll>mp;
void siz(ll v, ll e){
        sz[v]=1;
        for(const auto&[i,w]:g[v])
                if(i!=e and !used[i]) siz(i,v),sz[v]+=sz[i];
}
ll get(ll v, ll e, ll des){
        for(const auto&[i,w]:g[v])
                if(i!=e and !used[i] and sz[i]>des) return get(i,v,des);
        return v;
}
void help(ll v, ll e, ll km, ll d, bool fill){
        if(km>k) return;
        if(fill){
                if(!mp.count(km)) mp[km]=d;
                else mp[km]=min(mp[km],d);
        }
        else{
                if(km==k) res=min(res,d);
                else if(mp.count(k-km)) res=min(res,d+mp[k-km]);
        }
        for(const auto&[i,w]:g[v])
                if(i!=e and !used[i]) help(i,v,km+w,d+1,fill);
}
void decomp(ll v=0){
        siz(v,-1);
        ll c=get(v,-1,sz[v]>>1);
        used[c]=1;
        mp.clear();
        for(const auto&[i,w]:g[c])
                if(!used[i]){
                        help(i,c,w,1,0);
                        help(i,c,w,1,1);
                }
        for(const auto&[i,w]:g[c])
                if(!used[i]) decomp(i);
}
int best_path(int N, int K, int H[][2],int L[]){
        n=N;
        k=K;
        for(ll 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]});
        }
        decomp();
        if(res==1e7) res=-1;
        return res;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4948 KB Output is correct
2 Correct 3 ms 4948 KB Output is correct
3 Correct 2 ms 4948 KB Output is correct
4 Correct 3 ms 4948 KB Output is correct
5 Correct 4 ms 4952 KB Output is correct
6 Correct 3 ms 4948 KB Output is correct
7 Correct 3 ms 4948 KB Output is correct
8 Correct 3 ms 4948 KB Output is correct
9 Correct 3 ms 4948 KB Output is correct
10 Correct 3 ms 4948 KB Output is correct
11 Correct 3 ms 4948 KB Output is correct
12 Correct 2 ms 4948 KB Output is correct
13 Correct 3 ms 4948 KB Output is correct
14 Correct 3 ms 4948 KB Output is correct
15 Correct 2 ms 4948 KB Output is correct
16 Correct 3 ms 4948 KB Output is correct
17 Correct 3 ms 4948 KB Output is correct
18 Correct 3 ms 4948 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4948 KB Output is correct
2 Correct 3 ms 4948 KB Output is correct
3 Correct 2 ms 4948 KB Output is correct
4 Correct 3 ms 4948 KB Output is correct
5 Correct 4 ms 4952 KB Output is correct
6 Correct 3 ms 4948 KB Output is correct
7 Correct 3 ms 4948 KB Output is correct
8 Correct 3 ms 4948 KB Output is correct
9 Correct 3 ms 4948 KB Output is correct
10 Correct 3 ms 4948 KB Output is correct
11 Correct 3 ms 4948 KB Output is correct
12 Correct 2 ms 4948 KB Output is correct
13 Correct 3 ms 4948 KB Output is correct
14 Correct 3 ms 4948 KB Output is correct
15 Correct 2 ms 4948 KB Output is correct
16 Correct 3 ms 4948 KB Output is correct
17 Correct 3 ms 4948 KB Output is correct
18 Correct 3 ms 4948 KB Output is correct
19 Correct 3 ms 4948 KB Output is correct
20 Correct 2 ms 4948 KB Output is correct
21 Correct 4 ms 5076 KB Output is correct
22 Correct 3 ms 5076 KB Output is correct
23 Correct 3 ms 5076 KB Output is correct
24 Correct 4 ms 5076 KB Output is correct
25 Correct 4 ms 5076 KB Output is correct
26 Correct 3 ms 5076 KB Output is correct
27 Correct 3 ms 5076 KB Output is correct
28 Correct 4 ms 5132 KB Output is correct
29 Correct 4 ms 5076 KB Output is correct
30 Correct 4 ms 5076 KB Output is correct
31 Correct 4 ms 5076 KB Output is correct
32 Correct 4 ms 5148 KB Output is correct
33 Correct 4 ms 5076 KB Output is correct
34 Correct 3 ms 5048 KB Output is correct
35 Correct 3 ms 5076 KB Output is correct
36 Correct 3 ms 5076 KB Output is correct
37 Correct 4 ms 5076 KB Output is correct
38 Correct 3 ms 5076 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4948 KB Output is correct
2 Correct 3 ms 4948 KB Output is correct
3 Correct 2 ms 4948 KB Output is correct
4 Correct 3 ms 4948 KB Output is correct
5 Correct 4 ms 4952 KB Output is correct
6 Correct 3 ms 4948 KB Output is correct
7 Correct 3 ms 4948 KB Output is correct
8 Correct 3 ms 4948 KB Output is correct
9 Correct 3 ms 4948 KB Output is correct
10 Correct 3 ms 4948 KB Output is correct
11 Correct 3 ms 4948 KB Output is correct
12 Correct 2 ms 4948 KB Output is correct
13 Correct 3 ms 4948 KB Output is correct
14 Correct 3 ms 4948 KB Output is correct
15 Correct 2 ms 4948 KB Output is correct
16 Correct 3 ms 4948 KB Output is correct
17 Correct 3 ms 4948 KB Output is correct
18 Correct 3 ms 4948 KB Output is correct
19 Correct 179 ms 12088 KB Output is correct
20 Correct 175 ms 12056 KB Output is correct
21 Correct 187 ms 12128 KB Output is correct
22 Correct 181 ms 12160 KB Output is correct
23 Correct 75 ms 12536 KB Output is correct
24 Correct 70 ms 11744 KB Output is correct
25 Correct 125 ms 15008 KB Output is correct
26 Correct 93 ms 18004 KB Output is correct
27 Correct 173 ms 19856 KB Output is correct
28 Correct 253 ms 30948 KB Output is correct
29 Correct 245 ms 29964 KB Output is correct
30 Correct 173 ms 19792 KB Output is correct
31 Correct 177 ms 19820 KB Output is correct
32 Correct 194 ms 19732 KB Output is correct
33 Correct 252 ms 18620 KB Output is correct
34 Correct 172 ms 18636 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4948 KB Output is correct
2 Correct 3 ms 4948 KB Output is correct
3 Correct 2 ms 4948 KB Output is correct
4 Correct 3 ms 4948 KB Output is correct
5 Correct 4 ms 4952 KB Output is correct
6 Correct 3 ms 4948 KB Output is correct
7 Correct 3 ms 4948 KB Output is correct
8 Correct 3 ms 4948 KB Output is correct
9 Correct 3 ms 4948 KB Output is correct
10 Correct 3 ms 4948 KB Output is correct
11 Correct 3 ms 4948 KB Output is correct
12 Correct 2 ms 4948 KB Output is correct
13 Correct 3 ms 4948 KB Output is correct
14 Correct 3 ms 4948 KB Output is correct
15 Correct 2 ms 4948 KB Output is correct
16 Correct 3 ms 4948 KB Output is correct
17 Correct 3 ms 4948 KB Output is correct
18 Correct 3 ms 4948 KB Output is correct
19 Correct 3 ms 4948 KB Output is correct
20 Correct 2 ms 4948 KB Output is correct
21 Correct 4 ms 5076 KB Output is correct
22 Correct 3 ms 5076 KB Output is correct
23 Correct 3 ms 5076 KB Output is correct
24 Correct 4 ms 5076 KB Output is correct
25 Correct 4 ms 5076 KB Output is correct
26 Correct 3 ms 5076 KB Output is correct
27 Correct 3 ms 5076 KB Output is correct
28 Correct 4 ms 5132 KB Output is correct
29 Correct 4 ms 5076 KB Output is correct
30 Correct 4 ms 5076 KB Output is correct
31 Correct 4 ms 5076 KB Output is correct
32 Correct 4 ms 5148 KB Output is correct
33 Correct 4 ms 5076 KB Output is correct
34 Correct 3 ms 5048 KB Output is correct
35 Correct 3 ms 5076 KB Output is correct
36 Correct 3 ms 5076 KB Output is correct
37 Correct 4 ms 5076 KB Output is correct
38 Correct 3 ms 5076 KB Output is correct
39 Correct 179 ms 12088 KB Output is correct
40 Correct 175 ms 12056 KB Output is correct
41 Correct 187 ms 12128 KB Output is correct
42 Correct 181 ms 12160 KB Output is correct
43 Correct 75 ms 12536 KB Output is correct
44 Correct 70 ms 11744 KB Output is correct
45 Correct 125 ms 15008 KB Output is correct
46 Correct 93 ms 18004 KB Output is correct
47 Correct 173 ms 19856 KB Output is correct
48 Correct 253 ms 30948 KB Output is correct
49 Correct 245 ms 29964 KB Output is correct
50 Correct 173 ms 19792 KB Output is correct
51 Correct 177 ms 19820 KB Output is correct
52 Correct 194 ms 19732 KB Output is correct
53 Correct 252 ms 18620 KB Output is correct
54 Correct 172 ms 18636 KB Output is correct
55 Correct 19 ms 5836 KB Output is correct
56 Correct 16 ms 5736 KB Output is correct
57 Correct 130 ms 12492 KB Output is correct
58 Correct 39 ms 11708 KB Output is correct
59 Correct 266 ms 22756 KB Output is correct
60 Correct 820 ms 41872 KB Output is correct
61 Correct 239 ms 20040 KB Output is correct
62 Correct 260 ms 19900 KB Output is correct
63 Correct 329 ms 20096 KB Output is correct
64 Correct 942 ms 25560 KB Output is correct
65 Correct 203 ms 19264 KB Output is correct
66 Correct 510 ms 28256 KB Output is correct
67 Correct 108 ms 18564 KB Output is correct
68 Correct 356 ms 24256 KB Output is correct
69 Correct 386 ms 23688 KB Output is correct
70 Correct 329 ms 23244 KB Output is correct