답안 #900173

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
900173 2024-01-07T20:09:05 Z subrat0018 경주 (Race) (IOI11_race) C++17
100 / 100
552 ms 75964 KB
#include <bits/stdc++.h>
using namespace std;
#define nline "\n"
using uint = unsigned int;
const int M = 1e9 + 7;
const int M2 = 998244353;
const int INF = 1e9;
const int N = 1e6 + 10;
const double Degree = 57.2958;



int n,k;
int sz[N];
bool dead[N];
int dist[N];
vector<pair<int, int>> g[N];
vector<int> temp;
void prep(int v,int d, int len, int par = -1)
{
    if(len > k)return;
    dist[len] = min(dist[len], d);
    temp.push_back(len);
    for(auto &val:g[v])
    {
        if(val.first == par || dead[val.first])continue;
        prep(val.first, d + 1, len + val.second, v);
    }
}

int func(int v, int d, int len, int par = -1)
{
    if(len > k)return INF;
    int ans = d + dist[k - len];
    for(auto &val:g[v])
    {
        if(val.first == par || dead[val.first])continue;
        ans = min(ans, func(val.first, d + 1, len + val.second, v));
    }
    return ans;
}

void dfs(int v, int par=-1)
{
    sz[v] = 1;
    for(auto &val:g[v])
    {
        if(val.first != par && !dead[val.first])
        {
            dfs(val.first, v);
            sz[v] += sz[val.first];
        }
    }
}
int find_centroid(int currSize, int v, int par = -1)
{
    for(auto &val:g[v])
        if(val.first != par && !dead[val.first] && 2 * sz[val.first] > currSize)
            return find_centroid(currSize, val.first, v);
    return v;
}

int decompose(int v)
{
    dfs(v);
    int centorid = find_centroid(sz[v], v);
    dead[centorid] = true;
    
    int ans = INF;
    temp.clear();
    dist[0] = 0;
    for(auto &val:g[centorid])
    {
        if(!dead[val.first])
        {
            ans = min(func(val.first, 1, val.second, centorid), ans);
            prep(val.first, 1, val.second, centorid);
        }
    }
    dist[0] = INF;
    set<int> st(temp.begin(),temp.end());
    temp.clear();
    temp.assign(st.begin(),st.end());
    for(auto &val:temp)
        dist[val] = INF;
    for(auto &val:g[centorid])
        if(!dead[val.first])
            ans = min(ans, decompose(val.first));
    return ans;
}
int best_path(int nn, int K, int H[][2], int* L)
{
    n = nn;
    k = K;
    vector<pair<int, int>> arr;
    for(int i=0;i<N;i++)
        dist[i] = INF;
    for(int i=0;i<n-1;i++)
    {
        int u,v;
        u = H[i][0];
        v = H[i][1];
        arr.push_back({u,v});
    }
    int ct = 0;
    for(auto &val:arr)
    {
        int w;
        w = L[ct++];
        g[val.first].push_back({val.second, w});
        g[val.second].push_back({val.first, w});
    }
    int ans = decompose(0);
    if(ans >= INF)
        return -1;
    else
        return ans;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 33116 KB Output is correct
2 Correct 6 ms 33252 KB Output is correct
3 Correct 6 ms 33116 KB Output is correct
4 Correct 6 ms 33116 KB Output is correct
5 Correct 6 ms 33116 KB Output is correct
6 Correct 6 ms 33116 KB Output is correct
7 Correct 6 ms 33116 KB Output is correct
8 Correct 6 ms 33116 KB Output is correct
9 Correct 6 ms 33116 KB Output is correct
10 Correct 6 ms 33116 KB Output is correct
11 Correct 7 ms 33112 KB Output is correct
12 Correct 7 ms 33116 KB Output is correct
13 Correct 7 ms 33260 KB Output is correct
14 Correct 7 ms 33116 KB Output is correct
15 Correct 6 ms 33116 KB Output is correct
16 Correct 6 ms 33116 KB Output is correct
17 Correct 6 ms 33292 KB Output is correct
18 Correct 6 ms 33248 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 33116 KB Output is correct
2 Correct 6 ms 33252 KB Output is correct
3 Correct 6 ms 33116 KB Output is correct
4 Correct 6 ms 33116 KB Output is correct
5 Correct 6 ms 33116 KB Output is correct
6 Correct 6 ms 33116 KB Output is correct
7 Correct 6 ms 33116 KB Output is correct
8 Correct 6 ms 33116 KB Output is correct
9 Correct 6 ms 33116 KB Output is correct
10 Correct 6 ms 33116 KB Output is correct
11 Correct 7 ms 33112 KB Output is correct
12 Correct 7 ms 33116 KB Output is correct
13 Correct 7 ms 33260 KB Output is correct
14 Correct 7 ms 33116 KB Output is correct
15 Correct 6 ms 33116 KB Output is correct
16 Correct 6 ms 33116 KB Output is correct
17 Correct 6 ms 33292 KB Output is correct
18 Correct 6 ms 33248 KB Output is correct
19 Correct 8 ms 33228 KB Output is correct
20 Correct 7 ms 33116 KB Output is correct
21 Correct 8 ms 33116 KB Output is correct
22 Correct 7 ms 33116 KB Output is correct
23 Correct 9 ms 33272 KB Output is correct
24 Correct 8 ms 33116 KB Output is correct
25 Correct 8 ms 33216 KB Output is correct
26 Correct 7 ms 33116 KB Output is correct
27 Correct 7 ms 33116 KB Output is correct
28 Correct 7 ms 33372 KB Output is correct
29 Correct 7 ms 33240 KB Output is correct
30 Correct 8 ms 33272 KB Output is correct
31 Correct 7 ms 33368 KB Output is correct
32 Correct 8 ms 33372 KB Output is correct
33 Correct 8 ms 33372 KB Output is correct
34 Correct 7 ms 33116 KB Output is correct
35 Correct 8 ms 33116 KB Output is correct
36 Correct 7 ms 33116 KB Output is correct
37 Correct 7 ms 33372 KB Output is correct
38 Correct 8 ms 33392 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 33116 KB Output is correct
2 Correct 6 ms 33252 KB Output is correct
3 Correct 6 ms 33116 KB Output is correct
4 Correct 6 ms 33116 KB Output is correct
5 Correct 6 ms 33116 KB Output is correct
6 Correct 6 ms 33116 KB Output is correct
7 Correct 6 ms 33116 KB Output is correct
8 Correct 6 ms 33116 KB Output is correct
9 Correct 6 ms 33116 KB Output is correct
10 Correct 6 ms 33116 KB Output is correct
11 Correct 7 ms 33112 KB Output is correct
12 Correct 7 ms 33116 KB Output is correct
13 Correct 7 ms 33260 KB Output is correct
14 Correct 7 ms 33116 KB Output is correct
15 Correct 6 ms 33116 KB Output is correct
16 Correct 6 ms 33116 KB Output is correct
17 Correct 6 ms 33292 KB Output is correct
18 Correct 6 ms 33248 KB Output is correct
19 Correct 141 ms 39876 KB Output is correct
20 Correct 113 ms 41356 KB Output is correct
21 Correct 122 ms 41676 KB Output is correct
22 Correct 117 ms 42136 KB Output is correct
23 Correct 62 ms 41412 KB Output is correct
24 Correct 55 ms 41420 KB Output is correct
25 Correct 104 ms 43972 KB Output is correct
26 Correct 105 ms 47816 KB Output is correct
27 Correct 141 ms 47552 KB Output is correct
28 Correct 175 ms 58684 KB Output is correct
29 Correct 194 ms 57960 KB Output is correct
30 Correct 136 ms 47548 KB Output is correct
31 Correct 132 ms 47340 KB Output is correct
32 Correct 157 ms 47556 KB Output is correct
33 Correct 173 ms 46412 KB Output is correct
34 Correct 132 ms 47044 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 33116 KB Output is correct
2 Correct 6 ms 33252 KB Output is correct
3 Correct 6 ms 33116 KB Output is correct
4 Correct 6 ms 33116 KB Output is correct
5 Correct 6 ms 33116 KB Output is correct
6 Correct 6 ms 33116 KB Output is correct
7 Correct 6 ms 33116 KB Output is correct
8 Correct 6 ms 33116 KB Output is correct
9 Correct 6 ms 33116 KB Output is correct
10 Correct 6 ms 33116 KB Output is correct
11 Correct 7 ms 33112 KB Output is correct
12 Correct 7 ms 33116 KB Output is correct
13 Correct 7 ms 33260 KB Output is correct
14 Correct 7 ms 33116 KB Output is correct
15 Correct 6 ms 33116 KB Output is correct
16 Correct 6 ms 33116 KB Output is correct
17 Correct 6 ms 33292 KB Output is correct
18 Correct 6 ms 33248 KB Output is correct
19 Correct 8 ms 33228 KB Output is correct
20 Correct 7 ms 33116 KB Output is correct
21 Correct 8 ms 33116 KB Output is correct
22 Correct 7 ms 33116 KB Output is correct
23 Correct 9 ms 33272 KB Output is correct
24 Correct 8 ms 33116 KB Output is correct
25 Correct 8 ms 33216 KB Output is correct
26 Correct 7 ms 33116 KB Output is correct
27 Correct 7 ms 33116 KB Output is correct
28 Correct 7 ms 33372 KB Output is correct
29 Correct 7 ms 33240 KB Output is correct
30 Correct 8 ms 33272 KB Output is correct
31 Correct 7 ms 33368 KB Output is correct
32 Correct 8 ms 33372 KB Output is correct
33 Correct 8 ms 33372 KB Output is correct
34 Correct 7 ms 33116 KB Output is correct
35 Correct 8 ms 33116 KB Output is correct
36 Correct 7 ms 33116 KB Output is correct
37 Correct 7 ms 33372 KB Output is correct
38 Correct 8 ms 33392 KB Output is correct
39 Correct 141 ms 39876 KB Output is correct
40 Correct 113 ms 41356 KB Output is correct
41 Correct 122 ms 41676 KB Output is correct
42 Correct 117 ms 42136 KB Output is correct
43 Correct 62 ms 41412 KB Output is correct
44 Correct 55 ms 41420 KB Output is correct
45 Correct 104 ms 43972 KB Output is correct
46 Correct 105 ms 47816 KB Output is correct
47 Correct 141 ms 47552 KB Output is correct
48 Correct 175 ms 58684 KB Output is correct
49 Correct 194 ms 57960 KB Output is correct
50 Correct 136 ms 47548 KB Output is correct
51 Correct 132 ms 47340 KB Output is correct
52 Correct 157 ms 47556 KB Output is correct
53 Correct 173 ms 46412 KB Output is correct
54 Correct 132 ms 47044 KB Output is correct
55 Correct 17 ms 34140 KB Output is correct
56 Correct 16 ms 33916 KB Output is correct
57 Correct 94 ms 42216 KB Output is correct
58 Correct 36 ms 41936 KB Output is correct
59 Correct 177 ms 54508 KB Output is correct
60 Correct 517 ms 75964 KB Output is correct
61 Correct 168 ms 48000 KB Output is correct
62 Correct 183 ms 49344 KB Output is correct
63 Correct 201 ms 49344 KB Output is correct
64 Correct 552 ms 59712 KB Output is correct
65 Correct 115 ms 48320 KB Output is correct
66 Correct 375 ms 57284 KB Output is correct
67 Correct 100 ms 49848 KB Output is correct
68 Correct 241 ms 55484 KB Output is correct
69 Correct 242 ms 55744 KB Output is correct
70 Correct 245 ms 54720 KB Output is correct