답안 #725913

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
725913 2023-04-18T08:49:11 Z sofija6 경주 (Race) (IOI11_race) C++14
100 / 100
405 ms 37512 KB
#include <bits/stdc++.h>
#include "race.h"
#define MAXN 200010
#define MAXK 1000010
using namespace std;
vector<pair<int,int> > G[MAXN];
bool check[MAXN];
int subtree[MAXN],k,res=-1;
pair<int,int> ans[MAXK];
void DFS_Subtree(int i,int p)
{
    subtree[i]=1;
    for (auto next : G[i])
    {
        if (next.first!=p && !check[next.first])
        {
            DFS_Subtree(next.first,i);
            subtree[i]+=subtree[next.first];
        }
    }
}
int DFS_Centroid(int i,int p,int root)
{
    for (auto next : G[i])
    {
        if (next.first!=p && !check[next.first] && subtree[next.first]>subtree[root]/2)
            return DFS_Centroid(next.first,i,root);
    }
    return i;
}
int c;
void DFS_Paths(int i,int p,int d,int cnt)
{
    if (d>k)
        return;
    if (((ans[k-d].first && ans[k-d].second==c) || k==d) && (res==-1 || res>ans[k-d].first+cnt))
        res=ans[k-d].first+cnt;
    for (auto next : G[i])
    {
        if (next.first!=p && !check[next.first])
            DFS_Paths(next.first,i,d+next.second,cnt+1);
    }
}
void DFS_Fill(int i,int p,int d,int cnt)
{
    if (d>k)
        return;
    if (d && (!ans[d].first || ans[d].second!=c || ans[d].first>cnt))
        ans[d]={cnt,c};
    for (auto next : G[i])
    {
        if (next.first!=p && !check[next.first])
            DFS_Fill(next.first,i,d+next.second,cnt+1);
    }
}
void Solve(int i)
{
    DFS_Subtree(i,i);
    c=DFS_Centroid(i,i,i);
    check[c]=true;
    for (auto next : G[c])
    {
        if (check[next.first])
            continue;
        DFS_Paths(next.first,c,next.second,1);
        DFS_Fill(next.first,c,next.second,1);
    }
    for (auto next : G[c])
    {
        if (!check[next.first])
            Solve(next.first);
    }
}
int best_path(int N, int K, int H[][2], int L[])
{
    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]});
    }
    Solve(0);
    return res;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 4 ms 4948 KB Output is correct
3 Correct 3 ms 4948 KB Output is correct
4 Correct 3 ms 5024 KB Output is correct
5 Correct 3 ms 4948 KB Output is correct
6 Correct 3 ms 4948 KB Output is correct
7 Correct 3 ms 5004 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 4948 KB Output is correct
11 Correct 4 ms 4948 KB Output is correct
12 Correct 3 ms 5004 KB Output is correct
13 Correct 3 ms 4960 KB Output is correct
14 Correct 3 ms 5008 KB Output is correct
15 Correct 3 ms 4948 KB Output is correct
16 Correct 3 ms 4948 KB Output is correct
17 Correct 3 ms 4948 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 4 ms 4948 KB Output is correct
3 Correct 3 ms 4948 KB Output is correct
4 Correct 3 ms 5024 KB Output is correct
5 Correct 3 ms 4948 KB Output is correct
6 Correct 3 ms 4948 KB Output is correct
7 Correct 3 ms 5004 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 4948 KB Output is correct
11 Correct 4 ms 4948 KB Output is correct
12 Correct 3 ms 5004 KB Output is correct
13 Correct 3 ms 4960 KB Output is correct
14 Correct 3 ms 5008 KB Output is correct
15 Correct 3 ms 4948 KB Output is correct
16 Correct 3 ms 4948 KB Output is correct
17 Correct 3 ms 4948 KB Output is correct
18 Correct 3 ms 4948 KB Output is correct
19 Correct 3 ms 5040 KB Output is correct
20 Correct 3 ms 5000 KB Output is correct
21 Correct 4 ms 5008 KB Output is correct
22 Correct 7 ms 8340 KB Output is correct
23 Correct 5 ms 7892 KB Output is correct
24 Correct 6 ms 9112 KB Output is correct
25 Correct 6 ms 8216 KB Output is correct
26 Correct 5 ms 7380 KB Output is correct
27 Correct 3 ms 5020 KB Output is correct
28 Correct 4 ms 6552 KB Output is correct
29 Correct 5 ms 7448 KB Output is correct
30 Correct 5 ms 7764 KB Output is correct
31 Correct 6 ms 8340 KB Output is correct
32 Correct 6 ms 8404 KB Output is correct
33 Correct 7 ms 9812 KB Output is correct
34 Correct 5 ms 9044 KB Output is correct
35 Correct 6 ms 10068 KB Output is correct
36 Correct 6 ms 10324 KB Output is correct
37 Correct 7 ms 8280 KB Output is correct
38 Correct 4 ms 7252 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 4 ms 4948 KB Output is correct
3 Correct 3 ms 4948 KB Output is correct
4 Correct 3 ms 5024 KB Output is correct
5 Correct 3 ms 4948 KB Output is correct
6 Correct 3 ms 4948 KB Output is correct
7 Correct 3 ms 5004 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 4948 KB Output is correct
11 Correct 4 ms 4948 KB Output is correct
12 Correct 3 ms 5004 KB Output is correct
13 Correct 3 ms 4960 KB Output is correct
14 Correct 3 ms 5008 KB Output is correct
15 Correct 3 ms 4948 KB Output is correct
16 Correct 3 ms 4948 KB Output is correct
17 Correct 3 ms 4948 KB Output is correct
18 Correct 3 ms 4948 KB Output is correct
19 Correct 123 ms 11752 KB Output is correct
20 Correct 125 ms 11584 KB Output is correct
21 Correct 126 ms 11612 KB Output is correct
22 Correct 112 ms 11800 KB Output is correct
23 Correct 73 ms 11980 KB Output is correct
24 Correct 56 ms 11980 KB Output is correct
25 Correct 123 ms 15248 KB Output is correct
26 Correct 88 ms 18892 KB Output is correct
27 Correct 185 ms 18792 KB Output is correct
28 Correct 264 ms 33256 KB Output is correct
29 Correct 262 ms 32148 KB Output is correct
30 Correct 156 ms 18788 KB Output is correct
31 Correct 176 ms 18776 KB Output is correct
32 Correct 189 ms 18908 KB Output is correct
33 Correct 183 ms 17672 KB Output is correct
34 Correct 158 ms 18564 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 4 ms 4948 KB Output is correct
3 Correct 3 ms 4948 KB Output is correct
4 Correct 3 ms 5024 KB Output is correct
5 Correct 3 ms 4948 KB Output is correct
6 Correct 3 ms 4948 KB Output is correct
7 Correct 3 ms 5004 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 4948 KB Output is correct
11 Correct 4 ms 4948 KB Output is correct
12 Correct 3 ms 5004 KB Output is correct
13 Correct 3 ms 4960 KB Output is correct
14 Correct 3 ms 5008 KB Output is correct
15 Correct 3 ms 4948 KB Output is correct
16 Correct 3 ms 4948 KB Output is correct
17 Correct 3 ms 4948 KB Output is correct
18 Correct 3 ms 4948 KB Output is correct
19 Correct 3 ms 5040 KB Output is correct
20 Correct 3 ms 5000 KB Output is correct
21 Correct 4 ms 5008 KB Output is correct
22 Correct 7 ms 8340 KB Output is correct
23 Correct 5 ms 7892 KB Output is correct
24 Correct 6 ms 9112 KB Output is correct
25 Correct 6 ms 8216 KB Output is correct
26 Correct 5 ms 7380 KB Output is correct
27 Correct 3 ms 5020 KB Output is correct
28 Correct 4 ms 6552 KB Output is correct
29 Correct 5 ms 7448 KB Output is correct
30 Correct 5 ms 7764 KB Output is correct
31 Correct 6 ms 8340 KB Output is correct
32 Correct 6 ms 8404 KB Output is correct
33 Correct 7 ms 9812 KB Output is correct
34 Correct 5 ms 9044 KB Output is correct
35 Correct 6 ms 10068 KB Output is correct
36 Correct 6 ms 10324 KB Output is correct
37 Correct 7 ms 8280 KB Output is correct
38 Correct 4 ms 7252 KB Output is correct
39 Correct 123 ms 11752 KB Output is correct
40 Correct 125 ms 11584 KB Output is correct
41 Correct 126 ms 11612 KB Output is correct
42 Correct 112 ms 11800 KB Output is correct
43 Correct 73 ms 11980 KB Output is correct
44 Correct 56 ms 11980 KB Output is correct
45 Correct 123 ms 15248 KB Output is correct
46 Correct 88 ms 18892 KB Output is correct
47 Correct 185 ms 18792 KB Output is correct
48 Correct 264 ms 33256 KB Output is correct
49 Correct 262 ms 32148 KB Output is correct
50 Correct 156 ms 18788 KB Output is correct
51 Correct 176 ms 18776 KB Output is correct
52 Correct 189 ms 18908 KB Output is correct
53 Correct 183 ms 17672 KB Output is correct
54 Correct 158 ms 18564 KB Output is correct
55 Correct 10 ms 5736 KB Output is correct
56 Correct 12 ms 5588 KB Output is correct
57 Correct 72 ms 11892 KB Output is correct
58 Correct 34 ms 11556 KB Output is correct
59 Correct 81 ms 19728 KB Output is correct
60 Correct 370 ms 37272 KB Output is correct
61 Correct 163 ms 18940 KB Output is correct
62 Correct 168 ms 18888 KB Output is correct
63 Correct 235 ms 18944 KB Output is correct
64 Correct 405 ms 21280 KB Output is correct
65 Correct 201 ms 19616 KB Output is correct
66 Correct 333 ms 37512 KB Output is correct
67 Correct 99 ms 19460 KB Output is correct
68 Correct 219 ms 24896 KB Output is correct
69 Correct 220 ms 25152 KB Output is correct
70 Correct 215 ms 24268 KB Output is correct