# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
29396 | 2017-07-19T08:27:31 Z | dereotu | 경주 (Race) (IOI11_race) | C++14 | 2226 ms | 44512 KB |
#include "race.h" #include <bits/stdc++.h> #define pii pair<int,int> #define mp make_pair #define pb push_back #define st first #define nd second #define forr(i,A,B) for(int i=A;i<B;++i) #define space ' ' #define endl '\n' #define LL long long using namespace std; vector <pair<int,int> > adj[200005]; int ans=1e9; int used[200005],sub[200005]; int k; int calc_sub(int x,int y){//ok sub[x]=1; forr(i,0,adj[x].size()){ if(adj[x][i].nd!=y and !used[adj[x][i].nd]){ sub[x]+=calc_sub(adj[x][i].nd,x); } } return sub[x]; } int find_centroid(int x,int y,int treesize){//ok forr(i,0,adj[x].size()){ int u=adj[x][i].nd; if(!used[u] and u!=y and sub[u]>treesize/2){ return find_centroid(u,x,treesize); } } return x; } void dfs(int x,int y,int length,int path,map<int,int> &temp_map){ if(length>k) return; if(temp_map.find(length)==temp_map.end()){ temp_map[length]=path; } else{ temp_map[length]=min(temp_map[length],path); } forr(i,0,adj[x].size()){ int u=adj[x][i].nd; if(u!=y and !used[u]){ dfs(u,x,length+adj[x][i].st,path+1,temp_map); } } } void merge(map<int,int> &a,map<int,int> &b){ for(auto it=b.begin();it!=b.end();++it){ if(a.find(k-it->st)!=a.end()){ ans=min(ans,a[k-it->st]+it->nd); } } for(auto it=b.begin();it!=b.end();++it){ if(a.find(it->st)==a.end()){ a[it->st]=it->nd; } else a[it->st]=min(a[it->st],it->nd); } } void calc(int x){//ok map<int,int> main_map; main_map[0]=0; forr(i,0,adj[x].size()){ int u=adj[x][i].nd; if(!used[u]){ map<int,int> sub_map; dfs(u,x,adj[x][i].st,1,sub_map); merge(main_map,sub_map); } } } void solve(int x){ calc_sub(x,-1); int centroid=find_centroid(x,-1,sub[x]); used[centroid]=1; calc(centroid); forr(i,0,adj[centroid].size()){ int u=adj[centroid][i].nd; if(!used[u]){ solve(u); } } } int best_path(int N, int K, int H[][2], int L[]) { for(int i=0;i<N;i++){ adj[H[i][0]].pb(mp(L[i],H[i][1])); adj[H[i][1]].pb(mp(L[i],H[i][0])); } k=K; solve(0); if(ans==1e9) return -1; else return ans; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 6 ms | 4988 KB | Output is correct |
2 | Correct | 6 ms | 5224 KB | Output is correct |
3 | Correct | 6 ms | 5268 KB | Output is correct |
4 | Correct | 7 ms | 5348 KB | Output is correct |
5 | Correct | 5 ms | 5348 KB | Output is correct |
6 | Correct | 6 ms | 5348 KB | Output is correct |
7 | Correct | 6 ms | 5348 KB | Output is correct |
8 | Correct | 5 ms | 5348 KB | Output is correct |
9 | Correct | 7 ms | 5348 KB | Output is correct |
10 | Correct | 6 ms | 5348 KB | Output is correct |
11 | Correct | 8 ms | 5348 KB | Output is correct |
12 | Correct | 5 ms | 5348 KB | Output is correct |
13 | Correct | 6 ms | 5348 KB | Output is correct |
14 | Correct | 7 ms | 5348 KB | Output is correct |
15 | Correct | 6 ms | 5348 KB | Output is correct |
16 | Correct | 6 ms | 5348 KB | Output is correct |
17 | Correct | 5 ms | 5372 KB | Output is correct |
18 | Correct | 5 ms | 5372 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 6 ms | 4988 KB | Output is correct |
2 | Correct | 6 ms | 5224 KB | Output is correct |
3 | Correct | 6 ms | 5268 KB | Output is correct |
4 | Correct | 7 ms | 5348 KB | Output is correct |
5 | Correct | 5 ms | 5348 KB | Output is correct |
6 | Correct | 6 ms | 5348 KB | Output is correct |
7 | Correct | 6 ms | 5348 KB | Output is correct |
8 | Correct | 5 ms | 5348 KB | Output is correct |
9 | Correct | 7 ms | 5348 KB | Output is correct |
10 | Correct | 6 ms | 5348 KB | Output is correct |
11 | Correct | 8 ms | 5348 KB | Output is correct |
12 | Correct | 5 ms | 5348 KB | Output is correct |
13 | Correct | 6 ms | 5348 KB | Output is correct |
14 | Correct | 7 ms | 5348 KB | Output is correct |
15 | Correct | 6 ms | 5348 KB | Output is correct |
16 | Correct | 6 ms | 5348 KB | Output is correct |
17 | Correct | 5 ms | 5372 KB | Output is correct |
18 | Correct | 5 ms | 5372 KB | Output is correct |
19 | Correct | 5 ms | 5372 KB | Output is correct |
20 | Correct | 6 ms | 5372 KB | Output is correct |
21 | Correct | 8 ms | 5372 KB | Output is correct |
22 | Correct | 7 ms | 5372 KB | Output is correct |
23 | Correct | 6 ms | 5372 KB | Output is correct |
24 | Correct | 6 ms | 5372 KB | Output is correct |
25 | Correct | 8 ms | 5372 KB | Output is correct |
26 | Correct | 6 ms | 5376 KB | Output is correct |
27 | Correct | 7 ms | 5500 KB | Output is correct |
28 | Correct | 7 ms | 5500 KB | Output is correct |
29 | Correct | 10 ms | 5500 KB | Output is correct |
30 | Correct | 10 ms | 5500 KB | Output is correct |
31 | Correct | 10 ms | 5500 KB | Output is correct |
32 | Correct | 10 ms | 5500 KB | Output is correct |
33 | Correct | 11 ms | 5500 KB | Output is correct |
34 | Correct | 8 ms | 5500 KB | Output is correct |
35 | Correct | 8 ms | 5500 KB | Output is correct |
36 | Correct | 7 ms | 5500 KB | Output is correct |
37 | Correct | 9 ms | 5500 KB | Output is correct |
38 | Correct | 10 ms | 5500 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 6 ms | 4988 KB | Output is correct |
2 | Correct | 6 ms | 5224 KB | Output is correct |
3 | Correct | 6 ms | 5268 KB | Output is correct |
4 | Correct | 7 ms | 5348 KB | Output is correct |
5 | Correct | 5 ms | 5348 KB | Output is correct |
6 | Correct | 6 ms | 5348 KB | Output is correct |
7 | Correct | 6 ms | 5348 KB | Output is correct |
8 | Correct | 5 ms | 5348 KB | Output is correct |
9 | Correct | 7 ms | 5348 KB | Output is correct |
10 | Correct | 6 ms | 5348 KB | Output is correct |
11 | Correct | 8 ms | 5348 KB | Output is correct |
12 | Correct | 5 ms | 5348 KB | Output is correct |
13 | Correct | 6 ms | 5348 KB | Output is correct |
14 | Correct | 7 ms | 5348 KB | Output is correct |
15 | Correct | 6 ms | 5348 KB | Output is correct |
16 | Correct | 6 ms | 5348 KB | Output is correct |
17 | Correct | 5 ms | 5372 KB | Output is correct |
18 | Correct | 5 ms | 5372 KB | Output is correct |
19 | Correct | 358 ms | 11144 KB | Output is correct |
20 | Correct | 387 ms | 11144 KB | Output is correct |
21 | Correct | 310 ms | 11144 KB | Output is correct |
22 | Correct | 292 ms | 11144 KB | Output is correct |
23 | Correct | 207 ms | 11144 KB | Output is correct |
24 | Correct | 162 ms | 11144 KB | Output is correct |
25 | Correct | 301 ms | 12848 KB | Output is correct |
26 | Correct | 146 ms | 15100 KB | Output is correct |
27 | Correct | 400 ms | 16928 KB | Output is correct |
28 | Correct | 607 ms | 24828 KB | Output is correct |
29 | Correct | 522 ms | 24828 KB | Output is correct |
30 | Correct | 351 ms | 24828 KB | Output is correct |
31 | Correct | 332 ms | 24828 KB | Output is correct |
32 | Correct | 492 ms | 24828 KB | Output is correct |
33 | Correct | 783 ms | 24828 KB | Output is correct |
34 | Correct | 483 ms | 24828 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 6 ms | 4988 KB | Output is correct |
2 | Correct | 6 ms | 5224 KB | Output is correct |
3 | Correct | 6 ms | 5268 KB | Output is correct |
4 | Correct | 7 ms | 5348 KB | Output is correct |
5 | Correct | 5 ms | 5348 KB | Output is correct |
6 | Correct | 6 ms | 5348 KB | Output is correct |
7 | Correct | 6 ms | 5348 KB | Output is correct |
8 | Correct | 5 ms | 5348 KB | Output is correct |
9 | Correct | 7 ms | 5348 KB | Output is correct |
10 | Correct | 6 ms | 5348 KB | Output is correct |
11 | Correct | 8 ms | 5348 KB | Output is correct |
12 | Correct | 5 ms | 5348 KB | Output is correct |
13 | Correct | 6 ms | 5348 KB | Output is correct |
14 | Correct | 7 ms | 5348 KB | Output is correct |
15 | Correct | 6 ms | 5348 KB | Output is correct |
16 | Correct | 6 ms | 5348 KB | Output is correct |
17 | Correct | 5 ms | 5372 KB | Output is correct |
18 | Correct | 5 ms | 5372 KB | Output is correct |
19 | Correct | 5 ms | 5372 KB | Output is correct |
20 | Correct | 6 ms | 5372 KB | Output is correct |
21 | Correct | 8 ms | 5372 KB | Output is correct |
22 | Correct | 7 ms | 5372 KB | Output is correct |
23 | Correct | 6 ms | 5372 KB | Output is correct |
24 | Correct | 6 ms | 5372 KB | Output is correct |
25 | Correct | 8 ms | 5372 KB | Output is correct |
26 | Correct | 6 ms | 5376 KB | Output is correct |
27 | Correct | 7 ms | 5500 KB | Output is correct |
28 | Correct | 7 ms | 5500 KB | Output is correct |
29 | Correct | 10 ms | 5500 KB | Output is correct |
30 | Correct | 10 ms | 5500 KB | Output is correct |
31 | Correct | 10 ms | 5500 KB | Output is correct |
32 | Correct | 10 ms | 5500 KB | Output is correct |
33 | Correct | 11 ms | 5500 KB | Output is correct |
34 | Correct | 8 ms | 5500 KB | Output is correct |
35 | Correct | 8 ms | 5500 KB | Output is correct |
36 | Correct | 7 ms | 5500 KB | Output is correct |
37 | Correct | 9 ms | 5500 KB | Output is correct |
38 | Correct | 10 ms | 5500 KB | Output is correct |
39 | Correct | 358 ms | 11144 KB | Output is correct |
40 | Correct | 387 ms | 11144 KB | Output is correct |
41 | Correct | 310 ms | 11144 KB | Output is correct |
42 | Correct | 292 ms | 11144 KB | Output is correct |
43 | Correct | 207 ms | 11144 KB | Output is correct |
44 | Correct | 162 ms | 11144 KB | Output is correct |
45 | Correct | 301 ms | 12848 KB | Output is correct |
46 | Correct | 146 ms | 15100 KB | Output is correct |
47 | Correct | 400 ms | 16928 KB | Output is correct |
48 | Correct | 607 ms | 24828 KB | Output is correct |
49 | Correct | 522 ms | 24828 KB | Output is correct |
50 | Correct | 351 ms | 24828 KB | Output is correct |
51 | Correct | 332 ms | 24828 KB | Output is correct |
52 | Correct | 492 ms | 24828 KB | Output is correct |
53 | Correct | 783 ms | 24828 KB | Output is correct |
54 | Correct | 483 ms | 24828 KB | Output is correct |
55 | Correct | 39 ms | 24828 KB | Output is correct |
56 | Correct | 31 ms | 24828 KB | Output is correct |
57 | Correct | 278 ms | 24828 KB | Output is correct |
58 | Correct | 78 ms | 24828 KB | Output is correct |
59 | Correct | 639 ms | 26512 KB | Output is correct |
60 | Correct | 2226 ms | 44512 KB | Output is correct |
61 | Correct | 501 ms | 44512 KB | Output is correct |
62 | Correct | 611 ms | 44512 KB | Output is correct |
63 | Correct | 689 ms | 44512 KB | Output is correct |
64 | Correct | 1935 ms | 44512 KB | Output is correct |
65 | Correct | 320 ms | 44512 KB | Output is correct |
66 | Correct | 1172 ms | 44512 KB | Output is correct |
67 | Correct | 273 ms | 44512 KB | Output is correct |
68 | Correct | 723 ms | 44512 KB | Output is correct |
69 | Correct | 721 ms | 44512 KB | Output is correct |
70 | Correct | 647 ms | 44512 KB | Output is correct |