답안 #707659

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
707659 2023-03-09T16:47:34 Z JJAnawat 경주 (Race) (IOI11_race) C++17
100 / 100
499 ms 33864 KB
#include "race.h"
#include<bits/stdc++.h>

//#define int long long

using namespace std;

int sz[200005];
bitset<200005> rm(0);
vector<pair<int,int>> g[200005];
int mn[1000005];
int ans=1e9;
int n,k;

int dfs(int u,int p=0){
    sz[u]=1;
    for(auto [v,w]:g[u]){
        if(v==p||rm[v])
            continue;
        sz[u]+=dfs(v,u);
    }
    return sz[u];
}

int centroid(int u,int p,int ts){
    for(auto [v,w]:g[u]){
        if(v==p||rm[v])
            continue;
        if(sz[v]*2>ts)
            return centroid(v,u,ts);
    }
    return u;
}

void compute(int u,int p,int t,int dis,int lv){
    if(dis>k)
        return;
    if(t==0)//query
        ans=min(ans,lv+mn[k-dis]);
    else if(t==1)//update
        mn[dis]=min(mn[dis],lv);
    else{
        mn[dis]=mn[k-dis]=1e9;
    }
    for(auto [v,w]:g[u])
        if(v!=p&&!rm[v])
            compute(v,u,t,dis+w,lv+1);
}

void sol(int u){
    for(auto [v,w]:g[u])
        if(!rm[v])
            compute(v,u,2,w,1);
    mn[0]=0;
    for(auto [v,w]:g[u]){
        if(!rm[v]){
            compute(v,u,0,w,1);
            compute(v,u,1,w,1);
        }
    }
}

void buildcentroid(int u,int p){
    u=centroid(u,0,dfs(u,0));
    rm[u]=1;
    sol(u);
    for(auto [v,w]:g[u])
        if(!rm[v])
            buildcentroid(v,u);
}

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]});
    }
    for(int i=1;i<=1000000;i++)
        mn[i]=1e9;
    buildcentroid(0,0);
    if(ans==1e9)
        return -1;
    return ans;
}

# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 8916 KB Output is correct
2 Correct 5 ms 8856 KB Output is correct
3 Correct 4 ms 8848 KB Output is correct
4 Correct 5 ms 8852 KB Output is correct
5 Correct 5 ms 8852 KB Output is correct
6 Correct 5 ms 8916 KB Output is correct
7 Correct 5 ms 8916 KB Output is correct
8 Correct 5 ms 8916 KB Output is correct
9 Correct 5 ms 8916 KB Output is correct
10 Correct 5 ms 8856 KB Output is correct
11 Correct 5 ms 8916 KB Output is correct
12 Correct 4 ms 8852 KB Output is correct
13 Correct 5 ms 8916 KB Output is correct
14 Correct 5 ms 8916 KB Output is correct
15 Correct 5 ms 8852 KB Output is correct
16 Correct 5 ms 8852 KB Output is correct
17 Correct 5 ms 8944 KB Output is correct
18 Correct 5 ms 8916 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 8916 KB Output is correct
2 Correct 5 ms 8856 KB Output is correct
3 Correct 4 ms 8848 KB Output is correct
4 Correct 5 ms 8852 KB Output is correct
5 Correct 5 ms 8852 KB Output is correct
6 Correct 5 ms 8916 KB Output is correct
7 Correct 5 ms 8916 KB Output is correct
8 Correct 5 ms 8916 KB Output is correct
9 Correct 5 ms 8916 KB Output is correct
10 Correct 5 ms 8856 KB Output is correct
11 Correct 5 ms 8916 KB Output is correct
12 Correct 4 ms 8852 KB Output is correct
13 Correct 5 ms 8916 KB Output is correct
14 Correct 5 ms 8916 KB Output is correct
15 Correct 5 ms 8852 KB Output is correct
16 Correct 5 ms 8852 KB Output is correct
17 Correct 5 ms 8944 KB Output is correct
18 Correct 5 ms 8916 KB Output is correct
19 Correct 5 ms 8848 KB Output is correct
20 Correct 4 ms 8916 KB Output is correct
21 Correct 6 ms 8984 KB Output is correct
22 Correct 5 ms 8992 KB Output is correct
23 Correct 5 ms 8916 KB Output is correct
24 Correct 6 ms 8916 KB Output is correct
25 Correct 6 ms 8916 KB Output is correct
26 Correct 5 ms 8916 KB Output is correct
27 Correct 5 ms 9004 KB Output is correct
28 Correct 5 ms 8916 KB Output is correct
29 Correct 5 ms 8988 KB Output is correct
30 Correct 5 ms 8916 KB Output is correct
31 Correct 5 ms 8980 KB Output is correct
32 Correct 5 ms 8916 KB Output is correct
33 Correct 5 ms 8916 KB Output is correct
34 Correct 5 ms 8916 KB Output is correct
35 Correct 5 ms 8916 KB Output is correct
36 Correct 5 ms 8916 KB Output is correct
37 Correct 5 ms 8916 KB Output is correct
38 Correct 5 ms 8916 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 8916 KB Output is correct
2 Correct 5 ms 8856 KB Output is correct
3 Correct 4 ms 8848 KB Output is correct
4 Correct 5 ms 8852 KB Output is correct
5 Correct 5 ms 8852 KB Output is correct
6 Correct 5 ms 8916 KB Output is correct
7 Correct 5 ms 8916 KB Output is correct
8 Correct 5 ms 8916 KB Output is correct
9 Correct 5 ms 8916 KB Output is correct
10 Correct 5 ms 8856 KB Output is correct
11 Correct 5 ms 8916 KB Output is correct
12 Correct 4 ms 8852 KB Output is correct
13 Correct 5 ms 8916 KB Output is correct
14 Correct 5 ms 8916 KB Output is correct
15 Correct 5 ms 8852 KB Output is correct
16 Correct 5 ms 8852 KB Output is correct
17 Correct 5 ms 8944 KB Output is correct
18 Correct 5 ms 8916 KB Output is correct
19 Correct 119 ms 15432 KB Output is correct
20 Correct 128 ms 15504 KB Output is correct
21 Correct 134 ms 15520 KB Output is correct
22 Correct 118 ms 15620 KB Output is correct
23 Correct 69 ms 15776 KB Output is correct
24 Correct 52 ms 15740 KB Output is correct
25 Correct 119 ms 18236 KB Output is correct
26 Correct 92 ms 21220 KB Output is correct
27 Correct 154 ms 22416 KB Output is correct
28 Correct 218 ms 33864 KB Output is correct
29 Correct 244 ms 33084 KB Output is correct
30 Correct 163 ms 22396 KB Output is correct
31 Correct 156 ms 22524 KB Output is correct
32 Correct 179 ms 22592 KB Output is correct
33 Correct 196 ms 21452 KB Output is correct
34 Correct 155 ms 22260 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 8916 KB Output is correct
2 Correct 5 ms 8856 KB Output is correct
3 Correct 4 ms 8848 KB Output is correct
4 Correct 5 ms 8852 KB Output is correct
5 Correct 5 ms 8852 KB Output is correct
6 Correct 5 ms 8916 KB Output is correct
7 Correct 5 ms 8916 KB Output is correct
8 Correct 5 ms 8916 KB Output is correct
9 Correct 5 ms 8916 KB Output is correct
10 Correct 5 ms 8856 KB Output is correct
11 Correct 5 ms 8916 KB Output is correct
12 Correct 4 ms 8852 KB Output is correct
13 Correct 5 ms 8916 KB Output is correct
14 Correct 5 ms 8916 KB Output is correct
15 Correct 5 ms 8852 KB Output is correct
16 Correct 5 ms 8852 KB Output is correct
17 Correct 5 ms 8944 KB Output is correct
18 Correct 5 ms 8916 KB Output is correct
19 Correct 5 ms 8848 KB Output is correct
20 Correct 4 ms 8916 KB Output is correct
21 Correct 6 ms 8984 KB Output is correct
22 Correct 5 ms 8992 KB Output is correct
23 Correct 5 ms 8916 KB Output is correct
24 Correct 6 ms 8916 KB Output is correct
25 Correct 6 ms 8916 KB Output is correct
26 Correct 5 ms 8916 KB Output is correct
27 Correct 5 ms 9004 KB Output is correct
28 Correct 5 ms 8916 KB Output is correct
29 Correct 5 ms 8988 KB Output is correct
30 Correct 5 ms 8916 KB Output is correct
31 Correct 5 ms 8980 KB Output is correct
32 Correct 5 ms 8916 KB Output is correct
33 Correct 5 ms 8916 KB Output is correct
34 Correct 5 ms 8916 KB Output is correct
35 Correct 5 ms 8916 KB Output is correct
36 Correct 5 ms 8916 KB Output is correct
37 Correct 5 ms 8916 KB Output is correct
38 Correct 5 ms 8916 KB Output is correct
39 Correct 119 ms 15432 KB Output is correct
40 Correct 128 ms 15504 KB Output is correct
41 Correct 134 ms 15520 KB Output is correct
42 Correct 118 ms 15620 KB Output is correct
43 Correct 69 ms 15776 KB Output is correct
44 Correct 52 ms 15740 KB Output is correct
45 Correct 119 ms 18236 KB Output is correct
46 Correct 92 ms 21220 KB Output is correct
47 Correct 154 ms 22416 KB Output is correct
48 Correct 218 ms 33864 KB Output is correct
49 Correct 244 ms 33084 KB Output is correct
50 Correct 163 ms 22396 KB Output is correct
51 Correct 156 ms 22524 KB Output is correct
52 Correct 179 ms 22592 KB Output is correct
53 Correct 196 ms 21452 KB Output is correct
54 Correct 155 ms 22260 KB Output is correct
55 Correct 13 ms 9556 KB Output is correct
56 Correct 14 ms 9556 KB Output is correct
57 Correct 82 ms 15740 KB Output is correct
58 Correct 33 ms 15404 KB Output is correct
59 Correct 94 ms 21160 KB Output is correct
60 Correct 431 ms 33100 KB Output is correct
61 Correct 172 ms 22664 KB Output is correct
62 Correct 193 ms 22492 KB Output is correct
63 Correct 249 ms 22656 KB Output is correct
64 Correct 499 ms 22960 KB Output is correct
65 Correct 191 ms 23420 KB Output is correct
66 Correct 343 ms 31056 KB Output is correct
67 Correct 99 ms 23228 KB Output is correct
68 Correct 241 ms 23328 KB Output is correct
69 Correct 239 ms 23396 KB Output is correct
70 Correct 239 ms 22800 KB Output is correct