답안 #613601

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
613601 2022-07-30T07:21:50 Z PoonYaPat 경주 (Race) (IOI11_race) C++14
100 / 100
364 ms 36388 KB
#include "race.h"

#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> pii;

int ans=INT_MAX,sz[200001],k;
int dis[1000001];
int now[1000001];
vector<pii> adj[200001];
vector<int> temp,temp2;
bool mark[200001];

int find_sz(int x, int par) {
    sz[x]=1;
    for (auto s : adj[x]) {
        if (s.first==par || mark[s.first]) continue;
        sz[x]+=find_sz(s.first,x);
    }
    return sz[x];
}

int cen(int x, int par, int n) {
    for (auto s : adj[x]) {
        if (s.first!=par && !mark[s.first] && sz[s.first]>n/2) return cen(s.first,x,n);
    }
    return x;
}

void dfs(int x, int par, int d, int cnt) { // d=distance, consider node x
    if (d<k) {
        now[d]=min({now[d],cnt,dis[d]});

        temp2.push_back(d);
        temp.push_back(d);

        if (dis[k-d]!=INT_MAX) ans=min(ans,cnt+dis[k-d]);

        for (auto s : adj[x]) if (!mark[s.first] && s.first!=par) dfs(s.first,x,d+s.second,cnt+1);
    } else if (d==k) ans=min(ans,cnt);
}

void sol(int x) {
    int centroid=cen(x,x,find_sz(x,x));
    mark[centroid]=true;

    for (auto s : adj[centroid]) {
        if (mark[s.first]) continue;
        dfs(s.first,centroid,s.second,1);
        for (auto s : temp2) dis[s]=now[s];
        temp2.clear();
    }

    for (auto s : temp) dis[s]=INT_MAX,now[s]=INT_MAX;
    temp.clear();

    for (auto s : adj[centroid]) if (!mark[s.first]) sol(s.first);
}

int best_path(int n, int K, int H[][2], int L[]) {
    k=K;
    for (int i=1; i<=K; ++i) dis[i]=INT_MAX,now[i]=INT_MAX;
    for (int i=0; i<n-1; ++i) {
        adj[H[i][0]].push_back(pii(H[i][1],L[i]));
        adj[H[i][1]].push_back(pii(H[i][0],L[i]));
    }
    sol(1);
    if (ans==INT_MAX) return -1;
    return ans;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 3 ms 4948 KB Output is correct
3 Correct 3 ms 4948 KB Output is correct
4 Correct 3 ms 4948 KB Output is correct
5 Correct 2 ms 4948 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 5012 KB Output is correct
11 Correct 3 ms 4948 KB Output is correct
12 Correct 3 ms 5016 KB Output is correct
13 Correct 3 ms 5016 KB Output is correct
14 Correct 3 ms 4948 KB Output is correct
15 Correct 3 ms 5012 KB Output is correct
16 Correct 3 ms 4948 KB Output is correct
17 Correct 3 ms 5008 KB Output is correct
18 Correct 3 ms 4948 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 3 ms 4948 KB Output is correct
3 Correct 3 ms 4948 KB Output is correct
4 Correct 3 ms 4948 KB Output is correct
5 Correct 2 ms 4948 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 5012 KB Output is correct
11 Correct 3 ms 4948 KB Output is correct
12 Correct 3 ms 5016 KB Output is correct
13 Correct 3 ms 5016 KB Output is correct
14 Correct 3 ms 4948 KB Output is correct
15 Correct 3 ms 5012 KB Output is correct
16 Correct 3 ms 4948 KB Output is correct
17 Correct 3 ms 5008 KB Output is correct
18 Correct 3 ms 4948 KB Output is correct
19 Correct 2 ms 5008 KB Output is correct
20 Correct 4 ms 4948 KB Output is correct
21 Correct 3 ms 5016 KB Output is correct
22 Correct 7 ms 12244 KB Output is correct
23 Correct 7 ms 10964 KB Output is correct
24 Correct 8 ms 11860 KB Output is correct
25 Correct 9 ms 11584 KB Output is correct
26 Correct 5 ms 7648 KB Output is correct
27 Correct 7 ms 11348 KB Output is correct
28 Correct 4 ms 6556 KB Output is correct
29 Correct 5 ms 7636 KB Output is correct
30 Correct 4 ms 7892 KB Output is correct
31 Correct 6 ms 10144 KB Output is correct
32 Correct 6 ms 10708 KB Output is correct
33 Correct 7 ms 11220 KB Output is correct
34 Correct 5 ms 9684 KB Output is correct
35 Correct 6 ms 11348 KB Output is correct
36 Correct 7 ms 12372 KB Output is correct
37 Correct 7 ms 11288 KB Output is correct
38 Correct 5 ms 9044 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 3 ms 4948 KB Output is correct
3 Correct 3 ms 4948 KB Output is correct
4 Correct 3 ms 4948 KB Output is correct
5 Correct 2 ms 4948 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 5012 KB Output is correct
11 Correct 3 ms 4948 KB Output is correct
12 Correct 3 ms 5016 KB Output is correct
13 Correct 3 ms 5016 KB Output is correct
14 Correct 3 ms 4948 KB Output is correct
15 Correct 3 ms 5012 KB Output is correct
16 Correct 3 ms 4948 KB Output is correct
17 Correct 3 ms 5008 KB Output is correct
18 Correct 3 ms 4948 KB Output is correct
19 Correct 108 ms 11828 KB Output is correct
20 Correct 104 ms 11684 KB Output is correct
21 Correct 100 ms 12076 KB Output is correct
22 Correct 93 ms 12476 KB Output is correct
23 Correct 66 ms 12000 KB Output is correct
24 Correct 57 ms 11936 KB Output is correct
25 Correct 128 ms 16732 KB Output is correct
26 Correct 87 ms 18136 KB Output is correct
27 Correct 138 ms 18824 KB Output is correct
28 Correct 229 ms 29204 KB Output is correct
29 Correct 240 ms 25180 KB Output is correct
30 Correct 156 ms 18860 KB Output is correct
31 Correct 151 ms 18812 KB Output is correct
32 Correct 206 ms 18828 KB Output is correct
33 Correct 194 ms 17612 KB Output is correct
34 Correct 155 ms 18576 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 3 ms 4948 KB Output is correct
3 Correct 3 ms 4948 KB Output is correct
4 Correct 3 ms 4948 KB Output is correct
5 Correct 2 ms 4948 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 5012 KB Output is correct
11 Correct 3 ms 4948 KB Output is correct
12 Correct 3 ms 5016 KB Output is correct
13 Correct 3 ms 5016 KB Output is correct
14 Correct 3 ms 4948 KB Output is correct
15 Correct 3 ms 5012 KB Output is correct
16 Correct 3 ms 4948 KB Output is correct
17 Correct 3 ms 5008 KB Output is correct
18 Correct 3 ms 4948 KB Output is correct
19 Correct 2 ms 5008 KB Output is correct
20 Correct 4 ms 4948 KB Output is correct
21 Correct 3 ms 5016 KB Output is correct
22 Correct 7 ms 12244 KB Output is correct
23 Correct 7 ms 10964 KB Output is correct
24 Correct 8 ms 11860 KB Output is correct
25 Correct 9 ms 11584 KB Output is correct
26 Correct 5 ms 7648 KB Output is correct
27 Correct 7 ms 11348 KB Output is correct
28 Correct 4 ms 6556 KB Output is correct
29 Correct 5 ms 7636 KB Output is correct
30 Correct 4 ms 7892 KB Output is correct
31 Correct 6 ms 10144 KB Output is correct
32 Correct 6 ms 10708 KB Output is correct
33 Correct 7 ms 11220 KB Output is correct
34 Correct 5 ms 9684 KB Output is correct
35 Correct 6 ms 11348 KB Output is correct
36 Correct 7 ms 12372 KB Output is correct
37 Correct 7 ms 11288 KB Output is correct
38 Correct 5 ms 9044 KB Output is correct
39 Correct 108 ms 11828 KB Output is correct
40 Correct 104 ms 11684 KB Output is correct
41 Correct 100 ms 12076 KB Output is correct
42 Correct 93 ms 12476 KB Output is correct
43 Correct 66 ms 12000 KB Output is correct
44 Correct 57 ms 11936 KB Output is correct
45 Correct 128 ms 16732 KB Output is correct
46 Correct 87 ms 18136 KB Output is correct
47 Correct 138 ms 18824 KB Output is correct
48 Correct 229 ms 29204 KB Output is correct
49 Correct 240 ms 25180 KB Output is correct
50 Correct 156 ms 18860 KB Output is correct
51 Correct 151 ms 18812 KB Output is correct
52 Correct 206 ms 18828 KB Output is correct
53 Correct 194 ms 17612 KB Output is correct
54 Correct 155 ms 18576 KB Output is correct
55 Correct 9 ms 5716 KB Output is correct
56 Correct 10 ms 5716 KB Output is correct
57 Correct 77 ms 12728 KB Output is correct
58 Correct 32 ms 12544 KB Output is correct
59 Correct 89 ms 19700 KB Output is correct
60 Correct 342 ms 34524 KB Output is correct
61 Correct 159 ms 19184 KB Output is correct
62 Correct 173 ms 27604 KB Output is correct
63 Correct 220 ms 27596 KB Output is correct
64 Correct 364 ms 24524 KB Output is correct
65 Correct 192 ms 19664 KB Output is correct
66 Correct 362 ms 36388 KB Output is correct
67 Correct 110 ms 29060 KB Output is correct
68 Correct 219 ms 27848 KB Output is correct
69 Correct 233 ms 28048 KB Output is correct
70 Correct 210 ms 27320 KB Output is correct