답안 #413681

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
413681 2021-05-29T08:55:09 Z Mahmudul_Kabir 경주 (Race) (IOI11_race) C++14
100 / 100
1562 ms 46456 KB
#include "race.h"

#include <bits/stdc++.h>

#define sp <<" "
#define el <<"\n"
#define S second
#define F first
#define pb push_back
#define all(ar) ar.begin(),ar.end()
#define pii pair<int,int>


using namespace std;
using ll = long long;
using ld = long double;

const int mxr = 200005;
const int big = 2000000999;

int n,k,ans = big;
vector<vector<pii>> g;
bitset<mxr> ded;
vector<int> sz(mxr); 


void dfs(int v,int p){
  sz[v] = 1;
  for(pii r: g[v]){
    if(r.F == p || ded[r.F]) continue; 
    dfs(r.F,v); 
    sz[v] += sz[r.F]; 
  }
  return; 
}

int fcen(int v,int p,int lim){
  for(pii r: g[v]){
    if(r.F == p || ded[r.F]) continue;
    if(sz[r.F] > lim) return fcen(r.F,v,lim);
  }
  return v;
}

void fil(int v,int p,int cost,int dep,map<int,int> &dis,map<int,int> &cum){
  if(cost > k) return;
  if(cum.count(k - cost)) ans = min(ans, dep + cum[k - cost]);  
  dis[cost] = dis.count(cost) ? min(dis[cost],dep) : dep; 
  for(pii r: g[v]){
    if(r.F == p || ded[r.F]) continue;
    fil(r.F,v,cost + r.S,dep+1,dis,cum);
  }
  return;
}

void decompose(int v){
  dfs(v,-1);
  int lim = (sz[v]/2);
  int cen = fcen(v,-1,lim);  
  ded[cen] = 1;
  map<int,int> cum;  
  for(pii r: g[cen]){
    if(ded[r.F]) continue; 
    map<int,int> dis; 
    fil(r.F,cen,r.S,1,dis,cum);
    for(pii x: dis) cum[x.F] = cum.count(x.F) ? min(cum[x.F],x.S) : x.S; 
  } 
  if(cum.count(k)) ans = min(ans,cum[k]);  
  for(pii r: g[cen]){
    if(!ded[r.F]) decompose(r.F);
  }
}

int best_path(int N, int K, int H[][2], int L[])
{
  n = N;
  k = K;
  g.assign(n,{});
  for(int i = 1; i < n; i++){
    int a = H[i-1][0], b = H[i-1][1], c = L[i-1]; 
    g[a].pb({b,c});
    g[b].pb({a,c});
  } 
  decompose(0);
  return ans == big ? -1 : ans;
}


# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 1100 KB Output is correct
2 Correct 2 ms 1100 KB Output is correct
3 Correct 2 ms 1100 KB Output is correct
4 Correct 2 ms 1100 KB Output is correct
5 Correct 1 ms 1100 KB Output is correct
6 Correct 1 ms 1100 KB Output is correct
7 Correct 1 ms 1100 KB Output is correct
8 Correct 1 ms 1100 KB Output is correct
9 Correct 1 ms 1100 KB Output is correct
10 Correct 2 ms 1100 KB Output is correct
11 Correct 1 ms 1100 KB Output is correct
12 Correct 1 ms 1100 KB Output is correct
13 Correct 1 ms 1104 KB Output is correct
14 Correct 1 ms 1100 KB Output is correct
15 Correct 1 ms 1100 KB Output is correct
16 Correct 1 ms 1100 KB Output is correct
17 Correct 1 ms 1100 KB Output is correct
18 Correct 1 ms 1100 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 1100 KB Output is correct
2 Correct 2 ms 1100 KB Output is correct
3 Correct 2 ms 1100 KB Output is correct
4 Correct 2 ms 1100 KB Output is correct
5 Correct 1 ms 1100 KB Output is correct
6 Correct 1 ms 1100 KB Output is correct
7 Correct 1 ms 1100 KB Output is correct
8 Correct 1 ms 1100 KB Output is correct
9 Correct 1 ms 1100 KB Output is correct
10 Correct 2 ms 1100 KB Output is correct
11 Correct 1 ms 1100 KB Output is correct
12 Correct 1 ms 1100 KB Output is correct
13 Correct 1 ms 1104 KB Output is correct
14 Correct 1 ms 1100 KB Output is correct
15 Correct 1 ms 1100 KB Output is correct
16 Correct 1 ms 1100 KB Output is correct
17 Correct 1 ms 1100 KB Output is correct
18 Correct 1 ms 1100 KB Output is correct
19 Correct 1 ms 1100 KB Output is correct
20 Correct 1 ms 1100 KB Output is correct
21 Correct 4 ms 1100 KB Output is correct
22 Correct 2 ms 1100 KB Output is correct
23 Correct 2 ms 1100 KB Output is correct
24 Correct 2 ms 1100 KB Output is correct
25 Correct 5 ms 1228 KB Output is correct
26 Correct 2 ms 1100 KB Output is correct
27 Correct 2 ms 1100 KB Output is correct
28 Correct 3 ms 1228 KB Output is correct
29 Correct 3 ms 1228 KB Output is correct
30 Correct 4 ms 1228 KB Output is correct
31 Correct 3 ms 1228 KB Output is correct
32 Correct 3 ms 1228 KB Output is correct
33 Correct 5 ms 1228 KB Output is correct
34 Correct 5 ms 1100 KB Output is correct
35 Correct 3 ms 1100 KB Output is correct
36 Correct 3 ms 1100 KB Output is correct
37 Correct 3 ms 1228 KB Output is correct
38 Correct 3 ms 1144 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 1100 KB Output is correct
2 Correct 2 ms 1100 KB Output is correct
3 Correct 2 ms 1100 KB Output is correct
4 Correct 2 ms 1100 KB Output is correct
5 Correct 1 ms 1100 KB Output is correct
6 Correct 1 ms 1100 KB Output is correct
7 Correct 1 ms 1100 KB Output is correct
8 Correct 1 ms 1100 KB Output is correct
9 Correct 1 ms 1100 KB Output is correct
10 Correct 2 ms 1100 KB Output is correct
11 Correct 1 ms 1100 KB Output is correct
12 Correct 1 ms 1100 KB Output is correct
13 Correct 1 ms 1104 KB Output is correct
14 Correct 1 ms 1100 KB Output is correct
15 Correct 1 ms 1100 KB Output is correct
16 Correct 1 ms 1100 KB Output is correct
17 Correct 1 ms 1100 KB Output is correct
18 Correct 1 ms 1100 KB Output is correct
19 Correct 273 ms 8276 KB Output is correct
20 Correct 276 ms 9796 KB Output is correct
21 Correct 283 ms 9688 KB Output is correct
22 Correct 277 ms 9784 KB Output is correct
23 Correct 108 ms 9908 KB Output is correct
24 Correct 102 ms 9852 KB Output is correct
25 Correct 167 ms 12548 KB Output is correct
26 Correct 124 ms 15284 KB Output is correct
27 Correct 277 ms 18592 KB Output is correct
28 Correct 315 ms 29940 KB Output is correct
29 Correct 328 ms 29064 KB Output is correct
30 Correct 287 ms 18516 KB Output is correct
31 Correct 277 ms 18516 KB Output is correct
32 Correct 347 ms 18692 KB Output is correct
33 Correct 476 ms 17476 KB Output is correct
34 Correct 236 ms 18328 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 1100 KB Output is correct
2 Correct 2 ms 1100 KB Output is correct
3 Correct 2 ms 1100 KB Output is correct
4 Correct 2 ms 1100 KB Output is correct
5 Correct 1 ms 1100 KB Output is correct
6 Correct 1 ms 1100 KB Output is correct
7 Correct 1 ms 1100 KB Output is correct
8 Correct 1 ms 1100 KB Output is correct
9 Correct 1 ms 1100 KB Output is correct
10 Correct 2 ms 1100 KB Output is correct
11 Correct 1 ms 1100 KB Output is correct
12 Correct 1 ms 1100 KB Output is correct
13 Correct 1 ms 1104 KB Output is correct
14 Correct 1 ms 1100 KB Output is correct
15 Correct 1 ms 1100 KB Output is correct
16 Correct 1 ms 1100 KB Output is correct
17 Correct 1 ms 1100 KB Output is correct
18 Correct 1 ms 1100 KB Output is correct
19 Correct 1 ms 1100 KB Output is correct
20 Correct 1 ms 1100 KB Output is correct
21 Correct 4 ms 1100 KB Output is correct
22 Correct 2 ms 1100 KB Output is correct
23 Correct 2 ms 1100 KB Output is correct
24 Correct 2 ms 1100 KB Output is correct
25 Correct 5 ms 1228 KB Output is correct
26 Correct 2 ms 1100 KB Output is correct
27 Correct 2 ms 1100 KB Output is correct
28 Correct 3 ms 1228 KB Output is correct
29 Correct 3 ms 1228 KB Output is correct
30 Correct 4 ms 1228 KB Output is correct
31 Correct 3 ms 1228 KB Output is correct
32 Correct 3 ms 1228 KB Output is correct
33 Correct 5 ms 1228 KB Output is correct
34 Correct 5 ms 1100 KB Output is correct
35 Correct 3 ms 1100 KB Output is correct
36 Correct 3 ms 1100 KB Output is correct
37 Correct 3 ms 1228 KB Output is correct
38 Correct 3 ms 1144 KB Output is correct
39 Correct 273 ms 8276 KB Output is correct
40 Correct 276 ms 9796 KB Output is correct
41 Correct 283 ms 9688 KB Output is correct
42 Correct 277 ms 9784 KB Output is correct
43 Correct 108 ms 9908 KB Output is correct
44 Correct 102 ms 9852 KB Output is correct
45 Correct 167 ms 12548 KB Output is correct
46 Correct 124 ms 15284 KB Output is correct
47 Correct 277 ms 18592 KB Output is correct
48 Correct 315 ms 29940 KB Output is correct
49 Correct 328 ms 29064 KB Output is correct
50 Correct 287 ms 18516 KB Output is correct
51 Correct 277 ms 18516 KB Output is correct
52 Correct 347 ms 18692 KB Output is correct
53 Correct 476 ms 17476 KB Output is correct
54 Correct 236 ms 18328 KB Output is correct
55 Correct 28 ms 2252 KB Output is correct
56 Correct 22 ms 1940 KB Output is correct
57 Correct 182 ms 9836 KB Output is correct
58 Correct 60 ms 9580 KB Output is correct
59 Correct 602 ms 22340 KB Output is correct
60 Correct 1514 ms 46456 KB Output is correct
61 Correct 460 ms 18884 KB Output is correct
62 Correct 450 ms 18804 KB Output is correct
63 Correct 592 ms 18792 KB Output is correct
64 Correct 1562 ms 30108 KB Output is correct
65 Correct 269 ms 19516 KB Output is correct
66 Correct 995 ms 28572 KB Output is correct
67 Correct 174 ms 19336 KB Output is correct
68 Correct 594 ms 26188 KB Output is correct
69 Correct 591 ms 26560 KB Output is correct
70 Correct 602 ms 25348 KB Output is correct