답안 #790478

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
790478 2023-07-22T17:19:31 Z kilikuma 경주 (Race) (IOI11_race) C++14
100 / 100
247 ms 32832 KB
#include "race.h"
#include <bits/stdc++.h>
#define pii pair<int,int>
#define fi first
#define se second
#define pb push_back
using namespace std;
#define MAXN 200010
#define MAXK 1000010
vector<pii> adj[MAXN];
int N, K, siz[MAXN], res, b[MAXK];
bool vis[MAXN];
 
int dfsSize(int node, int prev) {
    siz[node] = 1;
    for(auto x : adj[node]) {
        if(x.fi != prev && !vis[x.fi]) siz[node] += dfsSize(x.fi, node);
    }
    return siz[node];
}
int dfsCentroid(int node, int prev, int S) {
    for(auto x : adj[node]) {
        if(x.fi != prev && !vis[x.fi] && siz[x.fi] > S/2) return dfsCentroid(x.fi, node, S);
    }
    return node;
}
 
vector<int> v;
vector<pii> vt;
void dfsSolve(int node, int prev, int len, int dub) {
    vt.pb({dub, len});
    v.pb(len);
    res = min(res, b[K-len]+dub);
    for(auto x : adj[node]) {
        if(x.fi != prev && !vis[x.fi] && len+x.se <= K) dfsSolve(x.fi, node, len+x.se, dub+1);
    }
}
 
void centroidDecomp(int node) {
    int S = dfsSize(node, node);
    node = dfsCentroid(node, node, S);
    vis[node] = 1;
    for(auto x : adj[node]) {
        if(!vis[x.fi] && x.se <= K) dfsSolve(x.fi, node, x.se, 1);
        for(auto y : vt) {
            b[y.se] = min(b[y.se], y.fi);
        }
        res = min(res, b[K]);
        vt.clear();
    }
    for(auto x : v) b[x] = N;
    v.clear();
    for(auto x : adj[node]) if(!vis[x.fi]) centroidDecomp(x.fi);
}
int best_path(int n, int k, int H[][2], int L[]) {
    N = n; K = k;
    for(int i = 0; i < N-1; i++) {
        adj[H[i][0]+1].pb({H[i][1]+1, L[i]});
        adj[H[i][1]+1].pb({H[i][0]+1, L[i]});
    }
    res = N;
    for(int i = 0; i <= K; i++) b[i] = N;
    centroidDecomp(1);
    return (res == N ? -1:res);
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4948 KB Output is correct
2 Correct 2 ms 4948 KB Output is correct
3 Correct 2 ms 5016 KB Output is correct
4 Correct 2 ms 4948 KB Output is correct
5 Correct 2 ms 4948 KB Output is correct
6 Correct 2 ms 4948 KB Output is correct
7 Correct 3 ms 5012 KB Output is correct
8 Correct 2 ms 4948 KB Output is correct
9 Correct 2 ms 4948 KB Output is correct
10 Correct 3 ms 5076 KB Output is correct
11 Correct 2 ms 4948 KB Output is correct
12 Correct 2 ms 4948 KB Output is correct
13 Correct 2 ms 4948 KB Output is correct
14 Correct 2 ms 4948 KB Output is correct
15 Correct 3 ms 5020 KB Output is correct
16 Correct 2 ms 4948 KB Output is correct
17 Correct 2 ms 4948 KB Output is correct
18 Correct 3 ms 5016 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4948 KB Output is correct
2 Correct 2 ms 4948 KB Output is correct
3 Correct 2 ms 5016 KB Output is correct
4 Correct 2 ms 4948 KB Output is correct
5 Correct 2 ms 4948 KB Output is correct
6 Correct 2 ms 4948 KB Output is correct
7 Correct 3 ms 5012 KB Output is correct
8 Correct 2 ms 4948 KB Output is correct
9 Correct 2 ms 4948 KB Output is correct
10 Correct 3 ms 5076 KB Output is correct
11 Correct 2 ms 4948 KB Output is correct
12 Correct 2 ms 4948 KB Output is correct
13 Correct 2 ms 4948 KB Output is correct
14 Correct 2 ms 4948 KB Output is correct
15 Correct 3 ms 5020 KB Output is correct
16 Correct 2 ms 4948 KB Output is correct
17 Correct 2 ms 4948 KB Output is correct
18 Correct 3 ms 5016 KB Output is correct
19 Correct 2 ms 4948 KB Output is correct
20 Correct 2 ms 5016 KB Output is correct
21 Correct 3 ms 5076 KB Output is correct
22 Correct 5 ms 8660 KB Output is correct
23 Correct 5 ms 7976 KB Output is correct
24 Correct 5 ms 8404 KB Output is correct
25 Correct 4 ms 8404 KB Output is correct
26 Correct 3 ms 6308 KB Output is correct
27 Correct 5 ms 8228 KB Output is correct
28 Correct 3 ms 5844 KB Output is correct
29 Correct 5 ms 6356 KB Output is correct
30 Correct 3 ms 6484 KB Output is correct
31 Correct 4 ms 7588 KB Output is correct
32 Correct 5 ms 7844 KB Output is correct
33 Correct 5 ms 8148 KB Output is correct
34 Correct 4 ms 7380 KB Output is correct
35 Correct 5 ms 8224 KB Output is correct
36 Correct 5 ms 8736 KB Output is correct
37 Correct 5 ms 8148 KB Output is correct
38 Correct 4 ms 6996 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4948 KB Output is correct
2 Correct 2 ms 4948 KB Output is correct
3 Correct 2 ms 5016 KB Output is correct
4 Correct 2 ms 4948 KB Output is correct
5 Correct 2 ms 4948 KB Output is correct
6 Correct 2 ms 4948 KB Output is correct
7 Correct 3 ms 5012 KB Output is correct
8 Correct 2 ms 4948 KB Output is correct
9 Correct 2 ms 4948 KB Output is correct
10 Correct 3 ms 5076 KB Output is correct
11 Correct 2 ms 4948 KB Output is correct
12 Correct 2 ms 4948 KB Output is correct
13 Correct 2 ms 4948 KB Output is correct
14 Correct 2 ms 4948 KB Output is correct
15 Correct 3 ms 5020 KB Output is correct
16 Correct 2 ms 4948 KB Output is correct
17 Correct 2 ms 4948 KB Output is correct
18 Correct 3 ms 5016 KB Output is correct
19 Correct 81 ms 10828 KB Output is correct
20 Correct 70 ms 10820 KB Output is correct
21 Correct 94 ms 11408 KB Output is correct
22 Correct 68 ms 11596 KB Output is correct
23 Correct 49 ms 10956 KB Output is correct
24 Correct 43 ms 10784 KB Output is correct
25 Correct 84 ms 13448 KB Output is correct
26 Correct 72 ms 17464 KB Output is correct
27 Correct 119 ms 16320 KB Output is correct
28 Correct 156 ms 27324 KB Output is correct
29 Correct 158 ms 26536 KB Output is correct
30 Correct 102 ms 16200 KB Output is correct
31 Correct 104 ms 16320 KB Output is correct
32 Correct 123 ms 16204 KB Output is correct
33 Correct 134 ms 15148 KB Output is correct
34 Correct 126 ms 15000 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4948 KB Output is correct
2 Correct 2 ms 4948 KB Output is correct
3 Correct 2 ms 5016 KB Output is correct
4 Correct 2 ms 4948 KB Output is correct
5 Correct 2 ms 4948 KB Output is correct
6 Correct 2 ms 4948 KB Output is correct
7 Correct 3 ms 5012 KB Output is correct
8 Correct 2 ms 4948 KB Output is correct
9 Correct 2 ms 4948 KB Output is correct
10 Correct 3 ms 5076 KB Output is correct
11 Correct 2 ms 4948 KB Output is correct
12 Correct 2 ms 4948 KB Output is correct
13 Correct 2 ms 4948 KB Output is correct
14 Correct 2 ms 4948 KB Output is correct
15 Correct 3 ms 5020 KB Output is correct
16 Correct 2 ms 4948 KB Output is correct
17 Correct 2 ms 4948 KB Output is correct
18 Correct 3 ms 5016 KB Output is correct
19 Correct 2 ms 4948 KB Output is correct
20 Correct 2 ms 5016 KB Output is correct
21 Correct 3 ms 5076 KB Output is correct
22 Correct 5 ms 8660 KB Output is correct
23 Correct 5 ms 7976 KB Output is correct
24 Correct 5 ms 8404 KB Output is correct
25 Correct 4 ms 8404 KB Output is correct
26 Correct 3 ms 6308 KB Output is correct
27 Correct 5 ms 8228 KB Output is correct
28 Correct 3 ms 5844 KB Output is correct
29 Correct 5 ms 6356 KB Output is correct
30 Correct 3 ms 6484 KB Output is correct
31 Correct 4 ms 7588 KB Output is correct
32 Correct 5 ms 7844 KB Output is correct
33 Correct 5 ms 8148 KB Output is correct
34 Correct 4 ms 7380 KB Output is correct
35 Correct 5 ms 8224 KB Output is correct
36 Correct 5 ms 8736 KB Output is correct
37 Correct 5 ms 8148 KB Output is correct
38 Correct 4 ms 6996 KB Output is correct
39 Correct 81 ms 10828 KB Output is correct
40 Correct 70 ms 10820 KB Output is correct
41 Correct 94 ms 11408 KB Output is correct
42 Correct 68 ms 11596 KB Output is correct
43 Correct 49 ms 10956 KB Output is correct
44 Correct 43 ms 10784 KB Output is correct
45 Correct 84 ms 13448 KB Output is correct
46 Correct 72 ms 17464 KB Output is correct
47 Correct 119 ms 16320 KB Output is correct
48 Correct 156 ms 27324 KB Output is correct
49 Correct 158 ms 26536 KB Output is correct
50 Correct 102 ms 16200 KB Output is correct
51 Correct 104 ms 16320 KB Output is correct
52 Correct 123 ms 16204 KB Output is correct
53 Correct 134 ms 15148 KB Output is correct
54 Correct 126 ms 15000 KB Output is correct
55 Correct 7 ms 5716 KB Output is correct
56 Correct 8 ms 5796 KB Output is correct
57 Correct 57 ms 11824 KB Output is correct
58 Correct 29 ms 11940 KB Output is correct
59 Correct 70 ms 18156 KB Output is correct
60 Correct 247 ms 32832 KB Output is correct
61 Correct 108 ms 16596 KB Output is correct
62 Correct 132 ms 21316 KB Output is correct
63 Correct 142 ms 21100 KB Output is correct
64 Correct 227 ms 20156 KB Output is correct
65 Correct 120 ms 16160 KB Output is correct
66 Correct 224 ms 28524 KB Output is correct
67 Correct 100 ms 22268 KB Output is correct
68 Correct 146 ms 20816 KB Output is correct
69 Correct 154 ms 20832 KB Output is correct
70 Correct 155 ms 20372 KB Output is correct