답안 #500614

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
500614 2021-12-31T15:04:21 Z Joo 경주 (Race) (IOI11_race) C++17
100 / 100
435 ms 101484 KB
#include "race.h"
#include <bits/stdc++.h>
#define DEBUG 0
using namespace std;
 
const int MAXN = 2e5+10;
 
int ans = MAXN;
map<long long, int> mp[MAXN];
vector<pair<int,int>> G[MAXN];
 
void dfs(int u, int p, int dep, long long d, long long k){
  mp[u][d] = dep;
  for(auto [v, w] : G[u]){
    if(v == p) continue;
    dfs(v, u, dep+1, d+w, k);
 
    if(mp[v].size() > mp[u].size()) swap(mp[v], mp[u]);
    for(auto &[key, val] : mp[v]){
      long long tmp = k-key+2*d;
      if(mp[u].count(tmp)) ans = min(ans, val+mp[u][tmp]-2*dep);
    }
    for(auto &[key, val] : mp[v]){
      if(mp[u].count(key)) mp[u][key] = min(mp[u][key], val);
      else mp[u][key] = val;
    }
  }
 
  if(mp[u].count(k+d)) ans = min(ans, mp[u][k+d]-dep);
 
}
 
int best_path(int N, int K, int H[][2], int L[])
{
  for(int i = 0; i < N-1; i++){
    int u = H[i][0], v = H[i][1];
    G[u].emplace_back(v, L[i]);
    G[v].emplace_back(u, L[i]);
  }
 
  dfs(0, 0, 0, 0, K);
 
  if(ans >= MAXN) ans = -1;
  return ans;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 14412 KB Output is correct
2 Correct 7 ms 14372 KB Output is correct
3 Correct 8 ms 14412 KB Output is correct
4 Correct 8 ms 14396 KB Output is correct
5 Correct 8 ms 14412 KB Output is correct
6 Correct 9 ms 14412 KB Output is correct
7 Correct 8 ms 14412 KB Output is correct
8 Correct 10 ms 14388 KB Output is correct
9 Correct 7 ms 14392 KB Output is correct
10 Correct 8 ms 14412 KB Output is correct
11 Correct 7 ms 14384 KB Output is correct
12 Correct 8 ms 14384 KB Output is correct
13 Correct 7 ms 14388 KB Output is correct
14 Correct 8 ms 14412 KB Output is correct
15 Correct 8 ms 14388 KB Output is correct
16 Correct 7 ms 14412 KB Output is correct
17 Correct 7 ms 14412 KB Output is correct
18 Correct 7 ms 14392 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 14412 KB Output is correct
2 Correct 7 ms 14372 KB Output is correct
3 Correct 8 ms 14412 KB Output is correct
4 Correct 8 ms 14396 KB Output is correct
5 Correct 8 ms 14412 KB Output is correct
6 Correct 9 ms 14412 KB Output is correct
7 Correct 8 ms 14412 KB Output is correct
8 Correct 10 ms 14388 KB Output is correct
9 Correct 7 ms 14392 KB Output is correct
10 Correct 8 ms 14412 KB Output is correct
11 Correct 7 ms 14384 KB Output is correct
12 Correct 8 ms 14384 KB Output is correct
13 Correct 7 ms 14388 KB Output is correct
14 Correct 8 ms 14412 KB Output is correct
15 Correct 8 ms 14388 KB Output is correct
16 Correct 7 ms 14412 KB Output is correct
17 Correct 7 ms 14412 KB Output is correct
18 Correct 7 ms 14392 KB Output is correct
19 Correct 8 ms 14284 KB Output is correct
20 Correct 7 ms 14412 KB Output is correct
21 Correct 9 ms 14540 KB Output is correct
22 Correct 8 ms 14636 KB Output is correct
23 Correct 8 ms 14660 KB Output is correct
24 Correct 9 ms 14668 KB Output is correct
25 Correct 9 ms 14656 KB Output is correct
26 Correct 8 ms 14668 KB Output is correct
27 Correct 8 ms 14532 KB Output is correct
28 Correct 9 ms 14664 KB Output is correct
29 Correct 9 ms 14668 KB Output is correct
30 Correct 9 ms 14644 KB Output is correct
31 Correct 9 ms 14664 KB Output is correct
32 Correct 9 ms 14656 KB Output is correct
33 Correct 11 ms 14728 KB Output is correct
34 Correct 8 ms 14524 KB Output is correct
35 Correct 8 ms 14520 KB Output is correct
36 Correct 9 ms 14536 KB Output is correct
37 Correct 8 ms 14540 KB Output is correct
38 Correct 11 ms 14652 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 14412 KB Output is correct
2 Correct 7 ms 14372 KB Output is correct
3 Correct 8 ms 14412 KB Output is correct
4 Correct 8 ms 14396 KB Output is correct
5 Correct 8 ms 14412 KB Output is correct
6 Correct 9 ms 14412 KB Output is correct
7 Correct 8 ms 14412 KB Output is correct
8 Correct 10 ms 14388 KB Output is correct
9 Correct 7 ms 14392 KB Output is correct
10 Correct 8 ms 14412 KB Output is correct
11 Correct 7 ms 14384 KB Output is correct
12 Correct 8 ms 14384 KB Output is correct
13 Correct 7 ms 14388 KB Output is correct
14 Correct 8 ms 14412 KB Output is correct
15 Correct 8 ms 14388 KB Output is correct
16 Correct 7 ms 14412 KB Output is correct
17 Correct 7 ms 14412 KB Output is correct
18 Correct 7 ms 14392 KB Output is correct
19 Correct 124 ms 35420 KB Output is correct
20 Correct 117 ms 36164 KB Output is correct
21 Correct 122 ms 35876 KB Output is correct
22 Correct 122 ms 35428 KB Output is correct
23 Correct 169 ms 48244 KB Output is correct
24 Correct 130 ms 38856 KB Output is correct
25 Correct 119 ms 35272 KB Output is correct
26 Correct 60 ms 41904 KB Output is correct
27 Correct 192 ms 46292 KB Output is correct
28 Correct 360 ms 82336 KB Output is correct
29 Correct 307 ms 80856 KB Output is correct
30 Correct 205 ms 46332 KB Output is correct
31 Correct 190 ms 46276 KB Output is correct
32 Correct 232 ms 46424 KB Output is correct
33 Correct 225 ms 51168 KB Output is correct
34 Correct 333 ms 84024 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 14412 KB Output is correct
2 Correct 7 ms 14372 KB Output is correct
3 Correct 8 ms 14412 KB Output is correct
4 Correct 8 ms 14396 KB Output is correct
5 Correct 8 ms 14412 KB Output is correct
6 Correct 9 ms 14412 KB Output is correct
7 Correct 8 ms 14412 KB Output is correct
8 Correct 10 ms 14388 KB Output is correct
9 Correct 7 ms 14392 KB Output is correct
10 Correct 8 ms 14412 KB Output is correct
11 Correct 7 ms 14384 KB Output is correct
12 Correct 8 ms 14384 KB Output is correct
13 Correct 7 ms 14388 KB Output is correct
14 Correct 8 ms 14412 KB Output is correct
15 Correct 8 ms 14388 KB Output is correct
16 Correct 7 ms 14412 KB Output is correct
17 Correct 7 ms 14412 KB Output is correct
18 Correct 7 ms 14392 KB Output is correct
19 Correct 8 ms 14284 KB Output is correct
20 Correct 7 ms 14412 KB Output is correct
21 Correct 9 ms 14540 KB Output is correct
22 Correct 8 ms 14636 KB Output is correct
23 Correct 8 ms 14660 KB Output is correct
24 Correct 9 ms 14668 KB Output is correct
25 Correct 9 ms 14656 KB Output is correct
26 Correct 8 ms 14668 KB Output is correct
27 Correct 8 ms 14532 KB Output is correct
28 Correct 9 ms 14664 KB Output is correct
29 Correct 9 ms 14668 KB Output is correct
30 Correct 9 ms 14644 KB Output is correct
31 Correct 9 ms 14664 KB Output is correct
32 Correct 9 ms 14656 KB Output is correct
33 Correct 11 ms 14728 KB Output is correct
34 Correct 8 ms 14524 KB Output is correct
35 Correct 8 ms 14520 KB Output is correct
36 Correct 9 ms 14536 KB Output is correct
37 Correct 8 ms 14540 KB Output is correct
38 Correct 11 ms 14652 KB Output is correct
39 Correct 124 ms 35420 KB Output is correct
40 Correct 117 ms 36164 KB Output is correct
41 Correct 122 ms 35876 KB Output is correct
42 Correct 122 ms 35428 KB Output is correct
43 Correct 169 ms 48244 KB Output is correct
44 Correct 130 ms 38856 KB Output is correct
45 Correct 119 ms 35272 KB Output is correct
46 Correct 60 ms 41904 KB Output is correct
47 Correct 192 ms 46292 KB Output is correct
48 Correct 360 ms 82336 KB Output is correct
49 Correct 307 ms 80856 KB Output is correct
50 Correct 205 ms 46332 KB Output is correct
51 Correct 190 ms 46276 KB Output is correct
52 Correct 232 ms 46424 KB Output is correct
53 Correct 225 ms 51168 KB Output is correct
54 Correct 333 ms 84024 KB Output is correct
55 Correct 22 ms 17448 KB Output is correct
56 Correct 18 ms 16232 KB Output is correct
57 Correct 74 ms 33500 KB Output is correct
58 Correct 54 ms 26748 KB Output is correct
59 Correct 105 ms 48136 KB Output is correct
60 Correct 315 ms 81196 KB Output is correct
61 Correct 215 ms 49732 KB Output is correct
62 Correct 195 ms 46328 KB Output is correct
63 Correct 229 ms 46424 KB Output is correct
64 Correct 435 ms 101484 KB Output is correct
65 Correct 427 ms 99564 KB Output is correct
66 Correct 324 ms 77988 KB Output is correct
67 Correct 181 ms 40784 KB Output is correct
68 Correct 326 ms 63252 KB Output is correct
69 Correct 361 ms 68368 KB Output is correct
70 Correct 307 ms 61392 KB Output is correct