Submission #1003606

# Submission time Handle Problem Language Result Execution time Memory
1003606 2024-06-20T13:53:52 Z ilef Race (IOI11_race) C++17
21 / 100
3000 ms 15452 KB
#include <bits/stdc++.h>
using namespace std;
const int inf=2e5+1;
const int MAXN=2e5+1;
//const int MAX_N=2e5+14;
const int KK=1e6+1;
int n,k;
int ans;
int mx_depth;
int cnt[KK];
bool removed[MAXN];
int subtree[MAXN];
vector<vector<pair<int,int>>>graph;
int treesize(int node,int parent){
    subtree[node]=1;
    for(auto [w,child]:graph[node]){
        if(child!=parent && !removed[child]){

            subtree[node]+=treesize(child,node);
        }
    }

    return subtree[node];
}
int findcentroid(int node,int parent,int treesz){
    int sz=treesz/2;
    for(auto[w,child]:graph[node]){
        if(child!=parent && !removed[child]&& treesize(child,node)>(sz)){
            return findcentroid(child,node,treesz);
        }
    }
    return node;
}
void getans(int sum,int node,int parent,int depth,bool filling){
    if (sum>k){
        return;
    }
    
    mx_depth=max(mx_depth,sum);
    if(filling==true){
    cnt[sum]=min(cnt[sum],depth);
    }
    else{
        if(cnt[k-sum]<inf){
        
            ans=min(ans,depth+cnt[k-sum]);
        }
    }
    for(auto[w,child]:graph[node]){
        if(child!=parent && ! removed[child]){
            getans(sum+w,child,node,depth+1,filling);
        }
    }
}
void centroid_decomp(int node,int parent){
    
    int centroid=findcentroid( node, parent,treesize(node,parent));
    removed[centroid]=true;
    cnt[0]=0;
    for(auto &[w,child]:graph[centroid]){
            if(!removed[child]){
             getans(w,child,centroid,1,false);
            getans(w,child,centroid,1,true);
            }
    }
   
    fill(cnt+1,cnt+mx_depth+1,inf);
    for(auto[w,i]:graph[centroid]){
        if(!removed[i]){
        centroid_decomp(i,centroid);}
    }
}
int best_path(int N,int K,int H[][2],int L[]){
    mx_depth=0;
    n=N;
    k=K;
    graph.resize(n);
    for(int i=0;i<n-1;i++){
        int u=H[i][0];
        int v=H[i][1];
        int w=L[i];
        graph[u].push_back({w,v});
        graph[v].push_back({w,u});
    }
    ans=inf;
    memset(cnt,inf,sizeof(cnt));
    memset(removed,false,sizeof(removed));
    centroid_decomp(0,0);
    if(ans>=inf)ans=-1;
    return ans;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4440 KB Output is correct
2 Correct 2 ms 4444 KB Output is correct
3 Correct 2 ms 4444 KB Output is correct
4 Correct 2 ms 4444 KB Output is correct
5 Correct 2 ms 4444 KB Output is correct
6 Correct 2 ms 4444 KB Output is correct
7 Correct 2 ms 4444 KB Output is correct
8 Correct 2 ms 4444 KB Output is correct
9 Correct 2 ms 4444 KB Output is correct
10 Correct 2 ms 4444 KB Output is correct
11 Correct 1 ms 4444 KB Output is correct
12 Correct 2 ms 4444 KB Output is correct
13 Correct 2 ms 4444 KB Output is correct
14 Correct 3 ms 4444 KB Output is correct
15 Correct 2 ms 4444 KB Output is correct
16 Correct 2 ms 4444 KB Output is correct
17 Correct 2 ms 4444 KB Output is correct
18 Correct 2 ms 4444 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4440 KB Output is correct
2 Correct 2 ms 4444 KB Output is correct
3 Correct 2 ms 4444 KB Output is correct
4 Correct 2 ms 4444 KB Output is correct
5 Correct 2 ms 4444 KB Output is correct
6 Correct 2 ms 4444 KB Output is correct
7 Correct 2 ms 4444 KB Output is correct
8 Correct 2 ms 4444 KB Output is correct
9 Correct 2 ms 4444 KB Output is correct
10 Correct 2 ms 4444 KB Output is correct
11 Correct 1 ms 4444 KB Output is correct
12 Correct 2 ms 4444 KB Output is correct
13 Correct 2 ms 4444 KB Output is correct
14 Correct 3 ms 4444 KB Output is correct
15 Correct 2 ms 4444 KB Output is correct
16 Correct 2 ms 4444 KB Output is correct
17 Correct 2 ms 4444 KB Output is correct
18 Correct 2 ms 4444 KB Output is correct
19 Correct 2 ms 4440 KB Output is correct
20 Correct 2 ms 4444 KB Output is correct
21 Correct 2 ms 4504 KB Output is correct
22 Correct 293 ms 4444 KB Output is correct
23 Correct 282 ms 4636 KB Output is correct
24 Correct 281 ms 4628 KB Output is correct
25 Correct 188 ms 4440 KB Output is correct
26 Correct 121 ms 4444 KB Output is correct
27 Correct 2 ms 4444 KB Output is correct
28 Correct 67 ms 4624 KB Output is correct
29 Correct 108 ms 4444 KB Output is correct
30 Correct 122 ms 4624 KB Output is correct
31 Correct 199 ms 4444 KB Output is correct
32 Correct 184 ms 4440 KB Output is correct
33 Correct 258 ms 4628 KB Output is correct
34 Correct 188 ms 4624 KB Output is correct
35 Correct 237 ms 4440 KB Output is correct
36 Correct 247 ms 4440 KB Output is correct
37 Correct 149 ms 4620 KB Output is correct
38 Correct 101 ms 4444 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4440 KB Output is correct
2 Correct 2 ms 4444 KB Output is correct
3 Correct 2 ms 4444 KB Output is correct
4 Correct 2 ms 4444 KB Output is correct
5 Correct 2 ms 4444 KB Output is correct
6 Correct 2 ms 4444 KB Output is correct
7 Correct 2 ms 4444 KB Output is correct
8 Correct 2 ms 4444 KB Output is correct
9 Correct 2 ms 4444 KB Output is correct
10 Correct 2 ms 4444 KB Output is correct
11 Correct 1 ms 4444 KB Output is correct
12 Correct 2 ms 4444 KB Output is correct
13 Correct 2 ms 4444 KB Output is correct
14 Correct 3 ms 4444 KB Output is correct
15 Correct 2 ms 4444 KB Output is correct
16 Correct 2 ms 4444 KB Output is correct
17 Correct 2 ms 4444 KB Output is correct
18 Correct 2 ms 4444 KB Output is correct
19 Correct 156 ms 12372 KB Output is correct
20 Correct 146 ms 13396 KB Output is correct
21 Correct 137 ms 12880 KB Output is correct
22 Correct 114 ms 13212 KB Output is correct
23 Correct 76 ms 13392 KB Output is correct
24 Correct 49 ms 13148 KB Output is correct
25 Execution timed out 3070 ms 15452 KB Time limit exceeded
26 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4440 KB Output is correct
2 Correct 2 ms 4444 KB Output is correct
3 Correct 2 ms 4444 KB Output is correct
4 Correct 2 ms 4444 KB Output is correct
5 Correct 2 ms 4444 KB Output is correct
6 Correct 2 ms 4444 KB Output is correct
7 Correct 2 ms 4444 KB Output is correct
8 Correct 2 ms 4444 KB Output is correct
9 Correct 2 ms 4444 KB Output is correct
10 Correct 2 ms 4444 KB Output is correct
11 Correct 1 ms 4444 KB Output is correct
12 Correct 2 ms 4444 KB Output is correct
13 Correct 2 ms 4444 KB Output is correct
14 Correct 3 ms 4444 KB Output is correct
15 Correct 2 ms 4444 KB Output is correct
16 Correct 2 ms 4444 KB Output is correct
17 Correct 2 ms 4444 KB Output is correct
18 Correct 2 ms 4444 KB Output is correct
19 Correct 2 ms 4440 KB Output is correct
20 Correct 2 ms 4444 KB Output is correct
21 Correct 2 ms 4504 KB Output is correct
22 Correct 293 ms 4444 KB Output is correct
23 Correct 282 ms 4636 KB Output is correct
24 Correct 281 ms 4628 KB Output is correct
25 Correct 188 ms 4440 KB Output is correct
26 Correct 121 ms 4444 KB Output is correct
27 Correct 2 ms 4444 KB Output is correct
28 Correct 67 ms 4624 KB Output is correct
29 Correct 108 ms 4444 KB Output is correct
30 Correct 122 ms 4624 KB Output is correct
31 Correct 199 ms 4444 KB Output is correct
32 Correct 184 ms 4440 KB Output is correct
33 Correct 258 ms 4628 KB Output is correct
34 Correct 188 ms 4624 KB Output is correct
35 Correct 237 ms 4440 KB Output is correct
36 Correct 247 ms 4440 KB Output is correct
37 Correct 149 ms 4620 KB Output is correct
38 Correct 101 ms 4444 KB Output is correct
39 Correct 156 ms 12372 KB Output is correct
40 Correct 146 ms 13396 KB Output is correct
41 Correct 137 ms 12880 KB Output is correct
42 Correct 114 ms 13212 KB Output is correct
43 Correct 76 ms 13392 KB Output is correct
44 Correct 49 ms 13148 KB Output is correct
45 Execution timed out 3070 ms 15452 KB Time limit exceeded
46 Halted 0 ms 0 KB -