답안 #446124

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
446124 2021-07-21T02:18:43 Z Deepesson 경주 (Race) (IOI11_race) C++17
100 / 100
537 ms 103500 KB
#include <bits/stdc++.h>
#define MAX 205000
typedef std::pair<int,int> pii;
int NA,KA;
std::vector<pii> con[MAX];
std::map<int,long long> mapa[MAX];
int prof[MAX];
int distancia[MAX];
long long count=1e6;
void merge(int a,int b) {
    if(mapa[a].size()<mapa[b].size())std::swap(mapa[a],mapa[b]);
    for(auto&x:mapa[b]){
        {
            auto it = mapa[a].find((KA-(x.first-distancia[a]))+distancia[a]);
            if(it!=mapa[a].end())count=std::min(count,it->second+x.second-(2*prof[a]));
        }
    }
    for(auto&x:mapa[b]){
        auto it = mapa[a].find(x.first);
        if(it==mapa[a].end())
            mapa[a][x.first]=x.second;
        else mapa[a][x.first]=std::min(x.second,mapa[a][x.first]);
    }
}
void dfs(int pos,int prev,int dist,int depth=0) {
    mapa[pos][dist]=depth;
    prof[pos]=depth;
    distancia[pos]=dist;
    for(auto&x:con[pos]){
        if(prev==x.first)continue;
        dfs(x.first,pos,dist+x.second,depth+1);
        merge(pos,x.first);
    }
}
int best_path(int N, int K, int H[][2], int L[])
{
    for(auto&x:mapa)x.clear();
    for(auto&x:con)x.clear();
    NA=N;KA=K;
    for(int i=0;i!=N-1;++i){
        int a,b,c;
        a=H[i][0],b=H[i][1],c=L[i];
        con[a].push_back({b,c});
        con[b].push_back({a,c});
    }
    dfs(0,-1,0);
    if(count==1e6)count=-1;
    return count;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 14708 KB Output is correct
2 Correct 11 ms 14772 KB Output is correct
3 Correct 11 ms 14668 KB Output is correct
4 Correct 12 ms 14668 KB Output is correct
5 Correct 11 ms 14704 KB Output is correct
6 Correct 11 ms 14668 KB Output is correct
7 Correct 11 ms 14668 KB Output is correct
8 Correct 11 ms 14668 KB Output is correct
9 Correct 11 ms 14668 KB Output is correct
10 Correct 11 ms 14668 KB Output is correct
11 Correct 11 ms 14668 KB Output is correct
12 Correct 11 ms 14760 KB Output is correct
13 Correct 11 ms 14664 KB Output is correct
14 Correct 11 ms 14716 KB Output is correct
15 Correct 11 ms 14668 KB Output is correct
16 Correct 11 ms 14712 KB Output is correct
17 Correct 11 ms 14668 KB Output is correct
18 Correct 11 ms 14668 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 14708 KB Output is correct
2 Correct 11 ms 14772 KB Output is correct
3 Correct 11 ms 14668 KB Output is correct
4 Correct 12 ms 14668 KB Output is correct
5 Correct 11 ms 14704 KB Output is correct
6 Correct 11 ms 14668 KB Output is correct
7 Correct 11 ms 14668 KB Output is correct
8 Correct 11 ms 14668 KB Output is correct
9 Correct 11 ms 14668 KB Output is correct
10 Correct 11 ms 14668 KB Output is correct
11 Correct 11 ms 14668 KB Output is correct
12 Correct 11 ms 14760 KB Output is correct
13 Correct 11 ms 14664 KB Output is correct
14 Correct 11 ms 14716 KB Output is correct
15 Correct 11 ms 14668 KB Output is correct
16 Correct 11 ms 14712 KB Output is correct
17 Correct 11 ms 14668 KB Output is correct
18 Correct 11 ms 14668 KB Output is correct
19 Correct 11 ms 14668 KB Output is correct
20 Correct 10 ms 14740 KB Output is correct
21 Correct 12 ms 15012 KB Output is correct
22 Correct 12 ms 15052 KB Output is correct
23 Correct 12 ms 15052 KB Output is correct
24 Correct 12 ms 14976 KB Output is correct
25 Correct 13 ms 15052 KB Output is correct
26 Correct 12 ms 15052 KB Output is correct
27 Correct 12 ms 14924 KB Output is correct
28 Correct 13 ms 14980 KB Output is correct
29 Correct 13 ms 15072 KB Output is correct
30 Correct 14 ms 14988 KB Output is correct
31 Correct 13 ms 15040 KB Output is correct
32 Correct 13 ms 15060 KB Output is correct
33 Correct 13 ms 15068 KB Output is correct
34 Correct 13 ms 14924 KB Output is correct
35 Correct 13 ms 14924 KB Output is correct
36 Correct 12 ms 14924 KB Output is correct
37 Correct 12 ms 14872 KB Output is correct
38 Correct 12 ms 14924 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 14708 KB Output is correct
2 Correct 11 ms 14772 KB Output is correct
3 Correct 11 ms 14668 KB Output is correct
4 Correct 12 ms 14668 KB Output is correct
5 Correct 11 ms 14704 KB Output is correct
6 Correct 11 ms 14668 KB Output is correct
7 Correct 11 ms 14668 KB Output is correct
8 Correct 11 ms 14668 KB Output is correct
9 Correct 11 ms 14668 KB Output is correct
10 Correct 11 ms 14668 KB Output is correct
11 Correct 11 ms 14668 KB Output is correct
12 Correct 11 ms 14760 KB Output is correct
13 Correct 11 ms 14664 KB Output is correct
14 Correct 11 ms 14716 KB Output is correct
15 Correct 11 ms 14668 KB Output is correct
16 Correct 11 ms 14712 KB Output is correct
17 Correct 11 ms 14668 KB Output is correct
18 Correct 11 ms 14668 KB Output is correct
19 Correct 140 ms 35880 KB Output is correct
20 Correct 141 ms 37208 KB Output is correct
21 Correct 151 ms 36996 KB Output is correct
22 Correct 150 ms 36760 KB Output is correct
23 Correct 195 ms 49312 KB Output is correct
24 Correct 150 ms 40000 KB Output is correct
25 Correct 117 ms 32288 KB Output is correct
26 Correct 72 ms 35324 KB Output is correct
27 Correct 225 ms 48068 KB Output is correct
28 Correct 325 ms 68588 KB Output is correct
29 Correct 369 ms 68408 KB Output is correct
30 Correct 230 ms 48068 KB Output is correct
31 Correct 236 ms 48272 KB Output is correct
32 Correct 307 ms 48276 KB Output is correct
33 Correct 272 ms 52804 KB Output is correct
34 Correct 393 ms 85852 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 14708 KB Output is correct
2 Correct 11 ms 14772 KB Output is correct
3 Correct 11 ms 14668 KB Output is correct
4 Correct 12 ms 14668 KB Output is correct
5 Correct 11 ms 14704 KB Output is correct
6 Correct 11 ms 14668 KB Output is correct
7 Correct 11 ms 14668 KB Output is correct
8 Correct 11 ms 14668 KB Output is correct
9 Correct 11 ms 14668 KB Output is correct
10 Correct 11 ms 14668 KB Output is correct
11 Correct 11 ms 14668 KB Output is correct
12 Correct 11 ms 14760 KB Output is correct
13 Correct 11 ms 14664 KB Output is correct
14 Correct 11 ms 14716 KB Output is correct
15 Correct 11 ms 14668 KB Output is correct
16 Correct 11 ms 14712 KB Output is correct
17 Correct 11 ms 14668 KB Output is correct
18 Correct 11 ms 14668 KB Output is correct
19 Correct 11 ms 14668 KB Output is correct
20 Correct 10 ms 14740 KB Output is correct
21 Correct 12 ms 15012 KB Output is correct
22 Correct 12 ms 15052 KB Output is correct
23 Correct 12 ms 15052 KB Output is correct
24 Correct 12 ms 14976 KB Output is correct
25 Correct 13 ms 15052 KB Output is correct
26 Correct 12 ms 15052 KB Output is correct
27 Correct 12 ms 14924 KB Output is correct
28 Correct 13 ms 14980 KB Output is correct
29 Correct 13 ms 15072 KB Output is correct
30 Correct 14 ms 14988 KB Output is correct
31 Correct 13 ms 15040 KB Output is correct
32 Correct 13 ms 15060 KB Output is correct
33 Correct 13 ms 15068 KB Output is correct
34 Correct 13 ms 14924 KB Output is correct
35 Correct 13 ms 14924 KB Output is correct
36 Correct 12 ms 14924 KB Output is correct
37 Correct 12 ms 14872 KB Output is correct
38 Correct 12 ms 14924 KB Output is correct
39 Correct 140 ms 35880 KB Output is correct
40 Correct 141 ms 37208 KB Output is correct
41 Correct 151 ms 36996 KB Output is correct
42 Correct 150 ms 36760 KB Output is correct
43 Correct 195 ms 49312 KB Output is correct
44 Correct 150 ms 40000 KB Output is correct
45 Correct 117 ms 32288 KB Output is correct
46 Correct 72 ms 35324 KB Output is correct
47 Correct 225 ms 48068 KB Output is correct
48 Correct 325 ms 68588 KB Output is correct
49 Correct 369 ms 68408 KB Output is correct
50 Correct 230 ms 48068 KB Output is correct
51 Correct 236 ms 48272 KB Output is correct
52 Correct 307 ms 48276 KB Output is correct
53 Correct 272 ms 52804 KB Output is correct
54 Correct 393 ms 85852 KB Output is correct
55 Correct 27 ms 17912 KB Output is correct
56 Correct 19 ms 16696 KB Output is correct
57 Correct 92 ms 34688 KB Output is correct
58 Correct 63 ms 27832 KB Output is correct
59 Correct 105 ms 41624 KB Output is correct
60 Correct 363 ms 68248 KB Output is correct
61 Correct 274 ms 51652 KB Output is correct
62 Correct 229 ms 48240 KB Output is correct
63 Correct 310 ms 48264 KB Output is correct
64 Correct 537 ms 103500 KB Output is correct
65 Correct 524 ms 101724 KB Output is correct
66 Correct 366 ms 68148 KB Output is correct
67 Correct 221 ms 42652 KB Output is correct
68 Correct 450 ms 65312 KB Output is correct
69 Correct 466 ms 70212 KB Output is correct
70 Correct 447 ms 63108 KB Output is correct