답안 #857832

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
857832 2023-10-07T04:21:18 Z sleepntsheep 경주 (Race) (IOI11_race) C++17
100 / 100
257 ms 36288 KB
#include <iostream>
#include <vector>
#include <cstring>
#include <algorithm>
#include <deque>
#include <set>
#include <utility>
#include <array>

using namespace std;
#define ALL(x) x.begin(), x.end()
#define N 200005
#define K 1000005

int n, k, sz[N], dead[N], z = 1e9, dp[K];
vector<pair<int, int>> g[N];
vector<int> accessed;

int dfs(int u, int p)
{
    sz[u] = 1;
    for (auto [w, v] : g[u]) if (v != p && !dead[v]) sz[u] += dfs(v, u);
    return sz[u];
}

int get_centroid(int u, int p, int tn)
{
    for (auto [w, v] : g[u]) if (v != p && !dead[v] && sz[v] * 2 >= tn) return get_centroid(v, u, tn);
    return u;
}

void count(int u, int p, int fil, int dis, int dep)
{
    if (dis > k) return;
    accessed.push_back(dis);
    if (fil) dp[dis] = min(dp[dis], dep);
    else z = min(z, dp[k-dis] + dep);
    for (auto [w, v] : g[u])
        if (v != p && !dead[v]) count(v, u, fil, dis+w, dep+1);
}

void decomp(int u)
{
    u = get_centroid(u, -1, dfs(u, -1));
    dead[u] = 1;

    dp[0] = 0;

    for (auto [w, v] : g[u]) if (!dead[v]) count(v, u, 0, w, 1), count(v, u, 1, w, 1);

    for (auto x : accessed) dp[x] = 1e9+40;
    accessed.clear();

    for (auto [w, v] : g[u]) if (!dead[v]) decomp(v);

}

int best_path(int n0, int k0, int h[][2], int l[])
{
    memset(dp, 63, sizeof dp);
    n=n0,k=k0;
    
    for (int i = 0; i < n-1; ++i)
    {
        int u = h[i][0], v = h[i][1], w=l[i];
        g[u].emplace_back(w, v), g[v].emplace_back(w, u);
    }

    decomp(0);

    return (z < 1e9) ? z : -1;
}

# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 12632 KB Output is correct
2 Correct 3 ms 12788 KB Output is correct
3 Correct 2 ms 12636 KB Output is correct
4 Correct 2 ms 12636 KB Output is correct
5 Correct 2 ms 12724 KB Output is correct
6 Correct 2 ms 12636 KB Output is correct
7 Correct 2 ms 12632 KB Output is correct
8 Correct 2 ms 12632 KB Output is correct
9 Correct 2 ms 12636 KB Output is correct
10 Correct 3 ms 12736 KB Output is correct
11 Correct 2 ms 12636 KB Output is correct
12 Correct 2 ms 12636 KB Output is correct
13 Correct 2 ms 12632 KB Output is correct
14 Correct 3 ms 12644 KB Output is correct
15 Correct 2 ms 12636 KB Output is correct
16 Correct 2 ms 12636 KB Output is correct
17 Correct 3 ms 12636 KB Output is correct
18 Correct 2 ms 12752 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 12632 KB Output is correct
2 Correct 3 ms 12788 KB Output is correct
3 Correct 2 ms 12636 KB Output is correct
4 Correct 2 ms 12636 KB Output is correct
5 Correct 2 ms 12724 KB Output is correct
6 Correct 2 ms 12636 KB Output is correct
7 Correct 2 ms 12632 KB Output is correct
8 Correct 2 ms 12632 KB Output is correct
9 Correct 2 ms 12636 KB Output is correct
10 Correct 3 ms 12736 KB Output is correct
11 Correct 2 ms 12636 KB Output is correct
12 Correct 2 ms 12636 KB Output is correct
13 Correct 2 ms 12632 KB Output is correct
14 Correct 3 ms 12644 KB Output is correct
15 Correct 2 ms 12636 KB Output is correct
16 Correct 2 ms 12636 KB Output is correct
17 Correct 3 ms 12636 KB Output is correct
18 Correct 2 ms 12752 KB Output is correct
19 Correct 2 ms 12636 KB Output is correct
20 Correct 2 ms 12636 KB Output is correct
21 Correct 2 ms 12636 KB Output is correct
22 Correct 2 ms 12636 KB Output is correct
23 Correct 2 ms 12636 KB Output is correct
24 Correct 2 ms 12636 KB Output is correct
25 Correct 2 ms 12636 KB Output is correct
26 Correct 2 ms 12636 KB Output is correct
27 Correct 3 ms 12636 KB Output is correct
28 Correct 2 ms 12636 KB Output is correct
29 Correct 3 ms 12636 KB Output is correct
30 Correct 3 ms 12636 KB Output is correct
31 Correct 2 ms 12636 KB Output is correct
32 Correct 2 ms 12636 KB Output is correct
33 Correct 3 ms 12636 KB Output is correct
34 Correct 2 ms 12636 KB Output is correct
35 Correct 3 ms 12636 KB Output is correct
36 Correct 2 ms 12636 KB Output is correct
37 Correct 2 ms 12636 KB Output is correct
38 Correct 2 ms 12636 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 12632 KB Output is correct
2 Correct 3 ms 12788 KB Output is correct
3 Correct 2 ms 12636 KB Output is correct
4 Correct 2 ms 12636 KB Output is correct
5 Correct 2 ms 12724 KB Output is correct
6 Correct 2 ms 12636 KB Output is correct
7 Correct 2 ms 12632 KB Output is correct
8 Correct 2 ms 12632 KB Output is correct
9 Correct 2 ms 12636 KB Output is correct
10 Correct 3 ms 12736 KB Output is correct
11 Correct 2 ms 12636 KB Output is correct
12 Correct 2 ms 12636 KB Output is correct
13 Correct 2 ms 12632 KB Output is correct
14 Correct 3 ms 12644 KB Output is correct
15 Correct 2 ms 12636 KB Output is correct
16 Correct 2 ms 12636 KB Output is correct
17 Correct 3 ms 12636 KB Output is correct
18 Correct 2 ms 12752 KB Output is correct
19 Correct 75 ms 19564 KB Output is correct
20 Correct 75 ms 19324 KB Output is correct
21 Correct 78 ms 19688 KB Output is correct
22 Correct 75 ms 20180 KB Output is correct
23 Correct 46 ms 19540 KB Output is correct
24 Correct 38 ms 19312 KB Output is correct
25 Correct 73 ms 22160 KB Output is correct
26 Correct 67 ms 25816 KB Output is correct
27 Correct 113 ms 24712 KB Output is correct
28 Correct 146 ms 35024 KB Output is correct
29 Correct 156 ms 34132 KB Output is correct
30 Correct 110 ms 23908 KB Output is correct
31 Correct 100 ms 24140 KB Output is correct
32 Correct 117 ms 24092 KB Output is correct
33 Correct 124 ms 22884 KB Output is correct
34 Correct 104 ms 22852 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 12632 KB Output is correct
2 Correct 3 ms 12788 KB Output is correct
3 Correct 2 ms 12636 KB Output is correct
4 Correct 2 ms 12636 KB Output is correct
5 Correct 2 ms 12724 KB Output is correct
6 Correct 2 ms 12636 KB Output is correct
7 Correct 2 ms 12632 KB Output is correct
8 Correct 2 ms 12632 KB Output is correct
9 Correct 2 ms 12636 KB Output is correct
10 Correct 3 ms 12736 KB Output is correct
11 Correct 2 ms 12636 KB Output is correct
12 Correct 2 ms 12636 KB Output is correct
13 Correct 2 ms 12632 KB Output is correct
14 Correct 3 ms 12644 KB Output is correct
15 Correct 2 ms 12636 KB Output is correct
16 Correct 2 ms 12636 KB Output is correct
17 Correct 3 ms 12636 KB Output is correct
18 Correct 2 ms 12752 KB Output is correct
19 Correct 2 ms 12636 KB Output is correct
20 Correct 2 ms 12636 KB Output is correct
21 Correct 2 ms 12636 KB Output is correct
22 Correct 2 ms 12636 KB Output is correct
23 Correct 2 ms 12636 KB Output is correct
24 Correct 2 ms 12636 KB Output is correct
25 Correct 2 ms 12636 KB Output is correct
26 Correct 2 ms 12636 KB Output is correct
27 Correct 3 ms 12636 KB Output is correct
28 Correct 2 ms 12636 KB Output is correct
29 Correct 3 ms 12636 KB Output is correct
30 Correct 3 ms 12636 KB Output is correct
31 Correct 2 ms 12636 KB Output is correct
32 Correct 2 ms 12636 KB Output is correct
33 Correct 3 ms 12636 KB Output is correct
34 Correct 2 ms 12636 KB Output is correct
35 Correct 3 ms 12636 KB Output is correct
36 Correct 2 ms 12636 KB Output is correct
37 Correct 2 ms 12636 KB Output is correct
38 Correct 2 ms 12636 KB Output is correct
39 Correct 75 ms 19564 KB Output is correct
40 Correct 75 ms 19324 KB Output is correct
41 Correct 78 ms 19688 KB Output is correct
42 Correct 75 ms 20180 KB Output is correct
43 Correct 46 ms 19540 KB Output is correct
44 Correct 38 ms 19312 KB Output is correct
45 Correct 73 ms 22160 KB Output is correct
46 Correct 67 ms 25816 KB Output is correct
47 Correct 113 ms 24712 KB Output is correct
48 Correct 146 ms 35024 KB Output is correct
49 Correct 156 ms 34132 KB Output is correct
50 Correct 110 ms 23908 KB Output is correct
51 Correct 100 ms 24140 KB Output is correct
52 Correct 117 ms 24092 KB Output is correct
53 Correct 124 ms 22884 KB Output is correct
54 Correct 104 ms 22852 KB Output is correct
55 Correct 7 ms 13148 KB Output is correct
56 Correct 8 ms 13328 KB Output is correct
57 Correct 55 ms 20440 KB Output is correct
58 Correct 28 ms 20700 KB Output is correct
59 Correct 72 ms 25928 KB Output is correct
60 Correct 236 ms 36288 KB Output is correct
61 Correct 105 ms 24316 KB Output is correct
62 Correct 140 ms 25540 KB Output is correct
63 Correct 131 ms 25544 KB Output is correct
64 Correct 257 ms 25316 KB Output is correct
65 Correct 107 ms 23892 KB Output is correct
66 Correct 202 ms 32116 KB Output is correct
67 Correct 66 ms 26564 KB Output is correct
68 Correct 165 ms 25028 KB Output is correct
69 Correct 138 ms 25068 KB Output is correct
70 Correct 129 ms 24516 KB Output is correct