답안 #116541

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
116541 2019-06-12T20:34:09 Z Runtime_error_ 경주 (Race) (IOI11_race) C++14
100 / 100
960 ms 54040 KB
//IOI 2011 Day1 Problem 2 Race
//Full solutions
#include "race.h"
#include <bits/stdc++.h>
using namespace std;
const int inf=1e6+9;
vector<pair<int,int> > v[inf],add;
bool blocked[inf];
int subtree[inf],level[inf],dis[inf],min_path[inf],parent[inf],n,k;

void dfs_size(int node,int par){

    subtree[node]=1;
    parent[node]=par;
    for(auto o:v[node])
        if(!blocked[o.first] && par!=o.first)
            dfs_size(o.first,node),
            subtree[node]+=subtree[o.first];
}

int dfs_add(int node,int l,int d,int par){

    if(d>k)
        return 1e9+9;

    add.push_back(make_pair(l,d));

    int ret=min_path[k-d]+l;

    for(auto o:v[node])
        if(o.first!=par && !blocked[o.first])
            ret=min(ret,dfs_add(o.first,l+1,d+o.second,node));

        return ret;
}

void dfs_remove(int node,int d,int par){

    if(d>k)
        return ;
    min_path[d]=1e9+9;
    for(auto o:v[node])
        if(!blocked[o.first] && par!=o.first)
            dfs_remove(o.first,d+o.second,node);
}

int solve(int centroid){

    min_path[0]=0;
    int ret=1e9+9;
    for(auto o:v[centroid]){

        if(blocked[o.first])
            continue;

        ret=min(ret,dfs_add(o.first,1,o.second,centroid));
        while(!add.empty())
            min_path[add.back().second]=min(min_path[add.back().second],add.back().first),
            add.pop_back();
    }
    dfs_remove(centroid,0,-1);
    return ret;
}

int create(int start){
    dfs_size(start,-1);

    int centroid=start,best=subtree[start];

    queue<int> q;
    q.push(start);
    while(!q.empty()){
        int u=q.front();
        q.pop();
        int sz=subtree[start]-subtree[u];
        for(auto o:v[u])
            if(!blocked[o.first] && parent[u]!=o.first)
                sz=max(sz,subtree[o.first] ),q.push(o.first);

        if(sz<best)
            best=sz,centroid=u;
    }
    blocked[centroid]=1;

    int ret=solve(centroid);

    for(auto o:v[centroid])
        if(!blocked[o.first])
            ret=min( ret,create( o.first ) );
    return ret;
}


int best_path(int N, int K, int H[][2], int L[]){

    n=N;
    k=K;
    for(int i=0;i<=K;i++)
        min_path[i]=1e9+9;

    for(int i=0;i<N-1;i++){
        int x=H[i][0],y=H[i][1],z=L[i];
        v[x].push_back(make_pair(y,z));
        v[y].push_back(make_pair(x,z));
    }
    int ret=create(0);
    if(ret>N)
        ret=-1;
    return ret;
}

Compilation message

race.cpp: In function 'int dfs_add(int, int, int, int)':
race.cpp:30:5: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
     for(auto o:v[node])
     ^~~
race.cpp:34:9: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
         return ret;
         ^~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 22 ms 23808 KB Output is correct
2 Correct 21 ms 23808 KB Output is correct
3 Correct 22 ms 23808 KB Output is correct
4 Correct 22 ms 23808 KB Output is correct
5 Correct 22 ms 23928 KB Output is correct
6 Correct 23 ms 23808 KB Output is correct
7 Correct 21 ms 23808 KB Output is correct
8 Correct 21 ms 23808 KB Output is correct
9 Correct 21 ms 23808 KB Output is correct
10 Correct 21 ms 23808 KB Output is correct
11 Correct 23 ms 23936 KB Output is correct
12 Correct 22 ms 23808 KB Output is correct
13 Correct 22 ms 23936 KB Output is correct
14 Correct 23 ms 23936 KB Output is correct
15 Correct 22 ms 23824 KB Output is correct
16 Correct 23 ms 23808 KB Output is correct
17 Correct 22 ms 23824 KB Output is correct
18 Correct 22 ms 23800 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 22 ms 23808 KB Output is correct
2 Correct 21 ms 23808 KB Output is correct
3 Correct 22 ms 23808 KB Output is correct
4 Correct 22 ms 23808 KB Output is correct
5 Correct 22 ms 23928 KB Output is correct
6 Correct 23 ms 23808 KB Output is correct
7 Correct 21 ms 23808 KB Output is correct
8 Correct 21 ms 23808 KB Output is correct
9 Correct 21 ms 23808 KB Output is correct
10 Correct 21 ms 23808 KB Output is correct
11 Correct 23 ms 23936 KB Output is correct
12 Correct 22 ms 23808 KB Output is correct
13 Correct 22 ms 23936 KB Output is correct
14 Correct 23 ms 23936 KB Output is correct
15 Correct 22 ms 23824 KB Output is correct
16 Correct 23 ms 23808 KB Output is correct
17 Correct 22 ms 23824 KB Output is correct
18 Correct 22 ms 23800 KB Output is correct
19 Correct 21 ms 23808 KB Output is correct
20 Correct 21 ms 23808 KB Output is correct
21 Correct 21 ms 23936 KB Output is correct
22 Correct 26 ms 27512 KB Output is correct
23 Correct 25 ms 26880 KB Output is correct
24 Correct 25 ms 27264 KB Output is correct
25 Correct 25 ms 27136 KB Output is correct
26 Correct 23 ms 25216 KB Output is correct
27 Correct 24 ms 26996 KB Output is correct
28 Correct 23 ms 24704 KB Output is correct
29 Correct 24 ms 25216 KB Output is correct
30 Correct 26 ms 25336 KB Output is correct
31 Correct 25 ms 26412 KB Output is correct
32 Correct 25 ms 26752 KB Output is correct
33 Correct 25 ms 27000 KB Output is correct
34 Correct 24 ms 26240 KB Output is correct
35 Correct 24 ms 27136 KB Output is correct
36 Correct 25 ms 27520 KB Output is correct
37 Correct 25 ms 27008 KB Output is correct
38 Correct 25 ms 25856 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 22 ms 23808 KB Output is correct
2 Correct 21 ms 23808 KB Output is correct
3 Correct 22 ms 23808 KB Output is correct
4 Correct 22 ms 23808 KB Output is correct
5 Correct 22 ms 23928 KB Output is correct
6 Correct 23 ms 23808 KB Output is correct
7 Correct 21 ms 23808 KB Output is correct
8 Correct 21 ms 23808 KB Output is correct
9 Correct 21 ms 23808 KB Output is correct
10 Correct 21 ms 23808 KB Output is correct
11 Correct 23 ms 23936 KB Output is correct
12 Correct 22 ms 23808 KB Output is correct
13 Correct 22 ms 23936 KB Output is correct
14 Correct 23 ms 23936 KB Output is correct
15 Correct 22 ms 23824 KB Output is correct
16 Correct 23 ms 23808 KB Output is correct
17 Correct 22 ms 23824 KB Output is correct
18 Correct 22 ms 23800 KB Output is correct
19 Correct 206 ms 30940 KB Output is correct
20 Correct 203 ms 31100 KB Output is correct
21 Correct 214 ms 31224 KB Output is correct
22 Correct 216 ms 31348 KB Output is correct
23 Correct 153 ms 31268 KB Output is correct
24 Correct 112 ms 31448 KB Output is correct
25 Correct 257 ms 33784 KB Output is correct
26 Correct 147 ms 37112 KB Output is correct
27 Correct 262 ms 38392 KB Output is correct
28 Correct 571 ms 49820 KB Output is correct
29 Correct 595 ms 48760 KB Output is correct
30 Correct 298 ms 38392 KB Output is correct
31 Correct 285 ms 38392 KB Output is correct
32 Correct 322 ms 38532 KB Output is correct
33 Correct 450 ms 37284 KB Output is correct
34 Correct 416 ms 38140 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 22 ms 23808 KB Output is correct
2 Correct 21 ms 23808 KB Output is correct
3 Correct 22 ms 23808 KB Output is correct
4 Correct 22 ms 23808 KB Output is correct
5 Correct 22 ms 23928 KB Output is correct
6 Correct 23 ms 23808 KB Output is correct
7 Correct 21 ms 23808 KB Output is correct
8 Correct 21 ms 23808 KB Output is correct
9 Correct 21 ms 23808 KB Output is correct
10 Correct 21 ms 23808 KB Output is correct
11 Correct 23 ms 23936 KB Output is correct
12 Correct 22 ms 23808 KB Output is correct
13 Correct 22 ms 23936 KB Output is correct
14 Correct 23 ms 23936 KB Output is correct
15 Correct 22 ms 23824 KB Output is correct
16 Correct 23 ms 23808 KB Output is correct
17 Correct 22 ms 23824 KB Output is correct
18 Correct 22 ms 23800 KB Output is correct
19 Correct 21 ms 23808 KB Output is correct
20 Correct 21 ms 23808 KB Output is correct
21 Correct 21 ms 23936 KB Output is correct
22 Correct 26 ms 27512 KB Output is correct
23 Correct 25 ms 26880 KB Output is correct
24 Correct 25 ms 27264 KB Output is correct
25 Correct 25 ms 27136 KB Output is correct
26 Correct 23 ms 25216 KB Output is correct
27 Correct 24 ms 26996 KB Output is correct
28 Correct 23 ms 24704 KB Output is correct
29 Correct 24 ms 25216 KB Output is correct
30 Correct 26 ms 25336 KB Output is correct
31 Correct 25 ms 26412 KB Output is correct
32 Correct 25 ms 26752 KB Output is correct
33 Correct 25 ms 27000 KB Output is correct
34 Correct 24 ms 26240 KB Output is correct
35 Correct 24 ms 27136 KB Output is correct
36 Correct 25 ms 27520 KB Output is correct
37 Correct 25 ms 27008 KB Output is correct
38 Correct 25 ms 25856 KB Output is correct
39 Correct 206 ms 30940 KB Output is correct
40 Correct 203 ms 31100 KB Output is correct
41 Correct 214 ms 31224 KB Output is correct
42 Correct 216 ms 31348 KB Output is correct
43 Correct 153 ms 31268 KB Output is correct
44 Correct 112 ms 31448 KB Output is correct
45 Correct 257 ms 33784 KB Output is correct
46 Correct 147 ms 37112 KB Output is correct
47 Correct 262 ms 38392 KB Output is correct
48 Correct 571 ms 49820 KB Output is correct
49 Correct 595 ms 48760 KB Output is correct
50 Correct 298 ms 38392 KB Output is correct
51 Correct 285 ms 38392 KB Output is correct
52 Correct 322 ms 38532 KB Output is correct
53 Correct 450 ms 37284 KB Output is correct
54 Correct 416 ms 38140 KB Output is correct
55 Correct 36 ms 24672 KB Output is correct
56 Correct 36 ms 24576 KB Output is correct
57 Correct 124 ms 31760 KB Output is correct
58 Correct 82 ms 31212 KB Output is correct
59 Correct 147 ms 37872 KB Output is correct
60 Correct 960 ms 54040 KB Output is correct
61 Correct 285 ms 38648 KB Output is correct
62 Correct 313 ms 42424 KB Output is correct
63 Correct 445 ms 42564 KB Output is correct
64 Correct 757 ms 41688 KB Output is correct
65 Correct 408 ms 39416 KB Output is correct
66 Correct 720 ms 51028 KB Output is correct
67 Correct 218 ms 43932 KB Output is correct
68 Correct 423 ms 43240 KB Output is correct
69 Correct 428 ms 43428 KB Output is correct
70 Correct 388 ms 42488 KB Output is correct