답안 #672498

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
672498 2022-12-16T10:41:22 Z ToroTN 경주 (Race) (IOI11_race) C++14
100 / 100
504 ms 35736 KB
#include "race.h"
#include<bits/stdc++.h>
using namespace std;
//#include "grader.cpp"
#define ll long long
#define pb push_back
#define X first
#define Y second
int n,ans=1e9,m,sz[200005],vis[200005],mn[1000005];
vector<pair<int,int> > v[200005];
void dfs_size(int u,int p)
{
    sz[u]=1;
    for(auto [node,w]:v[u])
    {
        if(vis[node]==0&&node!=p)
        {
            dfs_size(node,u);
            sz[u]+=sz[node];
        }
    }
}
int find_cen(int u,int p,int want)
{
    for(auto [node,w]:v[u])
    {
        if(node!=p&&vis[node]==0)
        {
            if(sz[node]>want)return find_cen(node,u,want);
        }
    }
    return u;
}
void compute(int u,int p,int type,int depth,int lv)
{
    //printf("%lld %lld %lld %lld %lld\n",u,p,type,depth,lv);
    if(depth>m)return;
    if(type==1)
    {
        ans=min(ans,lv+mn[m-depth]);
    }else if(type==0)
    {
        mn[depth]=min(mn[depth],lv);
    }else
    {
        mn[depth]=1e9,mn[m-depth]=1e9;
    }
    for(auto [node,w]:v[u])
    {
        if(node!=p&&vis[node]==0)compute(node,u,type,depth+w,lv+1);
    }
}
void centroid(int u)
{
    dfs_size(u,u);
    int cen=find_cen(u,u,sz[u]/2);
    //printf("cen=%d\n",cen);
    vis[cen]=1;
    for(auto [node,w]:v[cen])
    {
        if(vis[node]==0)compute(node,node,2,w,1);
    }
    mn[0]=0;
    for(auto [node,w]:v[cen])
    {
        if(vis[node]==0)
        {
            //printf("node=%lld\n",node);
            compute(node,node,1,w,1);
            /*for(int i=0;i<=m;i++)
            {
                printf("%lld ",mn[i]);
            }
            printf("\n");*/
            compute(node,node,0,w,1);
            /*for(int i=0;i<=m;i++)
            {
                printf("%lld ",mn[i]);
            }
            printf("\n");*/
        }
    }
    //printf("\n");
    for(auto [node,w]:v[cen])
    {
        if(vis[node]==0)
        {
            centroid(node);
        }
    }
    /*for(int i=1;i<=n;i++)
    {
        printf("%d ",vis[i]);
    }
    printf("\n");*/
}
int best_path(int N, int K, int H[][2], int L[])
{
    n=N,m=K;
    for(int i=0;i<n-1;i++)
    {
        v[H[i][0]+1].pb({H[i][1]+1,L[i]});
        v[H[i][1]+1].pb({H[i][0]+1,L[i]});
    }
    // for(int i=1;i<=n;i++)
    // {
    //     printf("i=%d\n",i);
    //     for(auto [node,w]:v[i])
    //     {
    //         printf("%d %d\n",node,w);
    //     }
    //     printf("\n");
    // }
    for(int i=1;i<=n;i++)vis[i]=0;
    for(int i=1;i<=1000000;i++)mn[i]=1e9;
    centroid(1);
    if(ans==1e9)return -1;
    return ans;
}

Compilation message

race.cpp: In function 'void dfs_size(int, int)':
race.cpp:14:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   14 |     for(auto [node,w]:v[u])
      |              ^
race.cpp: In function 'int find_cen(int, int, int)':
race.cpp:25:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   25 |     for(auto [node,w]:v[u])
      |              ^
race.cpp: In function 'void compute(int, int, int, int, int)':
race.cpp:48:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   48 |     for(auto [node,w]:v[u])
      |              ^
race.cpp: In function 'void centroid(int)':
race.cpp:59:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   59 |     for(auto [node,w]:v[cen])
      |              ^
race.cpp:64:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   64 |     for(auto [node,w]:v[cen])
      |              ^
race.cpp:84:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   84 |     for(auto [node,w]:v[cen])
      |              ^
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 8916 KB Output is correct
2 Correct 5 ms 8916 KB Output is correct
3 Correct 5 ms 8944 KB Output is correct
4 Correct 5 ms 8904 KB Output is correct
5 Correct 5 ms 8916 KB Output is correct
6 Correct 5 ms 8916 KB Output is correct
7 Correct 5 ms 8916 KB Output is correct
8 Correct 5 ms 8916 KB Output is correct
9 Correct 5 ms 8852 KB Output is correct
10 Correct 4 ms 8916 KB Output is correct
11 Correct 6 ms 8916 KB Output is correct
12 Correct 5 ms 8860 KB Output is correct
13 Correct 6 ms 8916 KB Output is correct
14 Correct 5 ms 8916 KB Output is correct
15 Correct 6 ms 8856 KB Output is correct
16 Correct 5 ms 8916 KB Output is correct
17 Correct 7 ms 8916 KB Output is correct
18 Correct 5 ms 8916 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 8916 KB Output is correct
2 Correct 5 ms 8916 KB Output is correct
3 Correct 5 ms 8944 KB Output is correct
4 Correct 5 ms 8904 KB Output is correct
5 Correct 5 ms 8916 KB Output is correct
6 Correct 5 ms 8916 KB Output is correct
7 Correct 5 ms 8916 KB Output is correct
8 Correct 5 ms 8916 KB Output is correct
9 Correct 5 ms 8852 KB Output is correct
10 Correct 4 ms 8916 KB Output is correct
11 Correct 6 ms 8916 KB Output is correct
12 Correct 5 ms 8860 KB Output is correct
13 Correct 6 ms 8916 KB Output is correct
14 Correct 5 ms 8916 KB Output is correct
15 Correct 6 ms 8856 KB Output is correct
16 Correct 5 ms 8916 KB Output is correct
17 Correct 7 ms 8916 KB Output is correct
18 Correct 5 ms 8916 KB Output is correct
19 Correct 5 ms 8916 KB Output is correct
20 Correct 5 ms 8916 KB Output is correct
21 Correct 5 ms 8916 KB Output is correct
22 Correct 5 ms 8992 KB Output is correct
23 Correct 5 ms 8916 KB Output is correct
24 Correct 5 ms 8916 KB Output is correct
25 Correct 5 ms 8916 KB Output is correct
26 Correct 5 ms 8916 KB Output is correct
27 Correct 5 ms 8916 KB Output is correct
28 Correct 6 ms 8916 KB Output is correct
29 Correct 5 ms 8916 KB Output is correct
30 Correct 5 ms 8916 KB Output is correct
31 Correct 6 ms 8916 KB Output is correct
32 Correct 6 ms 8996 KB Output is correct
33 Correct 6 ms 8916 KB Output is correct
34 Correct 6 ms 8992 KB Output is correct
35 Correct 5 ms 8916 KB Output is correct
36 Correct 5 ms 8980 KB Output is correct
37 Correct 5 ms 8916 KB Output is correct
38 Correct 8 ms 8916 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 8916 KB Output is correct
2 Correct 5 ms 8916 KB Output is correct
3 Correct 5 ms 8944 KB Output is correct
4 Correct 5 ms 8904 KB Output is correct
5 Correct 5 ms 8916 KB Output is correct
6 Correct 5 ms 8916 KB Output is correct
7 Correct 5 ms 8916 KB Output is correct
8 Correct 5 ms 8916 KB Output is correct
9 Correct 5 ms 8852 KB Output is correct
10 Correct 4 ms 8916 KB Output is correct
11 Correct 6 ms 8916 KB Output is correct
12 Correct 5 ms 8860 KB Output is correct
13 Correct 6 ms 8916 KB Output is correct
14 Correct 5 ms 8916 KB Output is correct
15 Correct 6 ms 8856 KB Output is correct
16 Correct 5 ms 8916 KB Output is correct
17 Correct 7 ms 8916 KB Output is correct
18 Correct 5 ms 8916 KB Output is correct
19 Correct 130 ms 15520 KB Output is correct
20 Correct 127 ms 15480 KB Output is correct
21 Correct 134 ms 15508 KB Output is correct
22 Correct 124 ms 15608 KB Output is correct
23 Correct 78 ms 15776 KB Output is correct
24 Correct 56 ms 15652 KB Output is correct
25 Correct 124 ms 19112 KB Output is correct
26 Correct 102 ms 22828 KB Output is correct
27 Correct 187 ms 21260 KB Output is correct
28 Correct 252 ms 35736 KB Output is correct
29 Correct 256 ms 34520 KB Output is correct
30 Correct 175 ms 21364 KB Output is correct
31 Correct 181 ms 21472 KB Output is correct
32 Correct 196 ms 21376 KB Output is correct
33 Correct 209 ms 20340 KB Output is correct
34 Correct 185 ms 20228 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 8916 KB Output is correct
2 Correct 5 ms 8916 KB Output is correct
3 Correct 5 ms 8944 KB Output is correct
4 Correct 5 ms 8904 KB Output is correct
5 Correct 5 ms 8916 KB Output is correct
6 Correct 5 ms 8916 KB Output is correct
7 Correct 5 ms 8916 KB Output is correct
8 Correct 5 ms 8916 KB Output is correct
9 Correct 5 ms 8852 KB Output is correct
10 Correct 4 ms 8916 KB Output is correct
11 Correct 6 ms 8916 KB Output is correct
12 Correct 5 ms 8860 KB Output is correct
13 Correct 6 ms 8916 KB Output is correct
14 Correct 5 ms 8916 KB Output is correct
15 Correct 6 ms 8856 KB Output is correct
16 Correct 5 ms 8916 KB Output is correct
17 Correct 7 ms 8916 KB Output is correct
18 Correct 5 ms 8916 KB Output is correct
19 Correct 5 ms 8916 KB Output is correct
20 Correct 5 ms 8916 KB Output is correct
21 Correct 5 ms 8916 KB Output is correct
22 Correct 5 ms 8992 KB Output is correct
23 Correct 5 ms 8916 KB Output is correct
24 Correct 5 ms 8916 KB Output is correct
25 Correct 5 ms 8916 KB Output is correct
26 Correct 5 ms 8916 KB Output is correct
27 Correct 5 ms 8916 KB Output is correct
28 Correct 6 ms 8916 KB Output is correct
29 Correct 5 ms 8916 KB Output is correct
30 Correct 5 ms 8916 KB Output is correct
31 Correct 6 ms 8916 KB Output is correct
32 Correct 6 ms 8996 KB Output is correct
33 Correct 6 ms 8916 KB Output is correct
34 Correct 6 ms 8992 KB Output is correct
35 Correct 5 ms 8916 KB Output is correct
36 Correct 5 ms 8980 KB Output is correct
37 Correct 5 ms 8916 KB Output is correct
38 Correct 8 ms 8916 KB Output is correct
39 Correct 130 ms 15520 KB Output is correct
40 Correct 127 ms 15480 KB Output is correct
41 Correct 134 ms 15508 KB Output is correct
42 Correct 124 ms 15608 KB Output is correct
43 Correct 78 ms 15776 KB Output is correct
44 Correct 56 ms 15652 KB Output is correct
45 Correct 124 ms 19112 KB Output is correct
46 Correct 102 ms 22828 KB Output is correct
47 Correct 187 ms 21260 KB Output is correct
48 Correct 252 ms 35736 KB Output is correct
49 Correct 256 ms 34520 KB Output is correct
50 Correct 175 ms 21364 KB Output is correct
51 Correct 181 ms 21472 KB Output is correct
52 Correct 196 ms 21376 KB Output is correct
53 Correct 209 ms 20340 KB Output is correct
54 Correct 185 ms 20228 KB Output is correct
55 Correct 13 ms 9604 KB Output is correct
56 Correct 14 ms 9556 KB Output is correct
57 Correct 85 ms 15820 KB Output is correct
58 Correct 37 ms 15652 KB Output is correct
59 Correct 107 ms 22868 KB Output is correct
60 Correct 494 ms 34956 KB Output is correct
61 Correct 220 ms 21316 KB Output is correct
62 Correct 196 ms 21460 KB Output is correct
63 Correct 300 ms 21492 KB Output is correct
64 Correct 504 ms 21124 KB Output is correct
65 Correct 227 ms 21300 KB Output is correct
66 Correct 382 ms 31780 KB Output is correct
67 Correct 141 ms 21628 KB Output is correct
68 Correct 260 ms 21468 KB Output is correct
69 Correct 256 ms 21628 KB Output is correct
70 Correct 272 ms 21168 KB Output is correct