답안 #491728

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
491728 2021-12-04T06:27:57 Z Soumya1 경주 (Race) (IOI11_race) C++17
100 / 100
423 ms 83084 KB
#include <bits/stdc++.h>
#include "race.h"
using namespace std;
const int mxN = 2e5 + 5;
vector<pair<int, int>> ad[mxN];
map<int, int> mp[mxN];
int ans = 1e9;
void dfs(int u, int p, int k, int d, int h) {
  mp[u][d] = h;
  for (auto [v, w] : ad[u]) {
    if (v == p) continue;
    dfs(v, u, k, d + w, h + 1);
    if (mp[v].size() > mp[u].size()) {
      swap(mp[u], mp[v]);
    }
    for (auto [i, j] : mp[v]) {
      if (k + 2 * d - i >= 0 && mp[u].find(k + 2 * d - i) != mp[u].end()) {
        ans = min(ans, mp[u][k + 2 * d - i] + mp[v][i] - 2 * h);
      }
    }
    for (auto [i, j] : mp[v]) {
      if (!mp[u][i]) mp[u][i] = j;
      else mp[u][i] = min(mp[u][i], j);
    }
  }
}
int best_path(int N, int K, int H[][2], int L[]) {
  for (int i = 0; i < N - 1; i++) {
    ad[H[i][0] + 1].push_back({H[i][1] + 1, L[i]});
    ad[H[i][1] + 1].push_back({H[i][0] + 1, L[i]});
  }
  dfs(1, -1, K, 0, 1);
  if (ans == 1e9) ans = -1;
  return ans;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 14412 KB Output is correct
2 Correct 7 ms 14324 KB Output is correct
3 Correct 7 ms 14376 KB Output is correct
4 Correct 8 ms 14412 KB Output is correct
5 Correct 8 ms 14424 KB Output is correct
6 Correct 7 ms 14412 KB Output is correct
7 Correct 7 ms 14420 KB Output is correct
8 Correct 7 ms 14412 KB Output is correct
9 Correct 7 ms 14340 KB Output is correct
10 Correct 7 ms 14392 KB Output is correct
11 Correct 7 ms 14412 KB Output is correct
12 Correct 7 ms 14412 KB Output is correct
13 Correct 8 ms 14384 KB Output is correct
14 Correct 7 ms 14412 KB Output is correct
15 Correct 7 ms 14324 KB Output is correct
16 Correct 7 ms 14396 KB Output is correct
17 Correct 8 ms 14412 KB Output is correct
18 Correct 7 ms 14412 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 14412 KB Output is correct
2 Correct 7 ms 14324 KB Output is correct
3 Correct 7 ms 14376 KB Output is correct
4 Correct 8 ms 14412 KB Output is correct
5 Correct 8 ms 14424 KB Output is correct
6 Correct 7 ms 14412 KB Output is correct
7 Correct 7 ms 14420 KB Output is correct
8 Correct 7 ms 14412 KB Output is correct
9 Correct 7 ms 14340 KB Output is correct
10 Correct 7 ms 14392 KB Output is correct
11 Correct 7 ms 14412 KB Output is correct
12 Correct 7 ms 14412 KB Output is correct
13 Correct 8 ms 14384 KB Output is correct
14 Correct 7 ms 14412 KB Output is correct
15 Correct 7 ms 14324 KB Output is correct
16 Correct 7 ms 14396 KB Output is correct
17 Correct 8 ms 14412 KB Output is correct
18 Correct 7 ms 14412 KB Output is correct
19 Correct 8 ms 14284 KB Output is correct
20 Correct 7 ms 14412 KB Output is correct
21 Correct 8 ms 14516 KB Output is correct
22 Correct 9 ms 14532 KB Output is correct
23 Correct 9 ms 14540 KB Output is correct
24 Correct 9 ms 14532 KB Output is correct
25 Correct 11 ms 14532 KB Output is correct
26 Correct 11 ms 14540 KB Output is correct
27 Correct 8 ms 14540 KB Output is correct
28 Correct 9 ms 14540 KB Output is correct
29 Correct 10 ms 14596 KB Output is correct
30 Correct 8 ms 14540 KB Output is correct
31 Correct 8 ms 14536 KB Output is correct
32 Correct 8 ms 14540 KB Output is correct
33 Correct 8 ms 14660 KB Output is correct
34 Correct 9 ms 14532 KB Output is correct
35 Correct 8 ms 14524 KB Output is correct
36 Correct 8 ms 14548 KB Output is correct
37 Correct 8 ms 14528 KB Output is correct
38 Correct 8 ms 14588 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 14412 KB Output is correct
2 Correct 7 ms 14324 KB Output is correct
3 Correct 7 ms 14376 KB Output is correct
4 Correct 8 ms 14412 KB Output is correct
5 Correct 8 ms 14424 KB Output is correct
6 Correct 7 ms 14412 KB Output is correct
7 Correct 7 ms 14420 KB Output is correct
8 Correct 7 ms 14412 KB Output is correct
9 Correct 7 ms 14340 KB Output is correct
10 Correct 7 ms 14392 KB Output is correct
11 Correct 7 ms 14412 KB Output is correct
12 Correct 7 ms 14412 KB Output is correct
13 Correct 8 ms 14384 KB Output is correct
14 Correct 7 ms 14412 KB Output is correct
15 Correct 7 ms 14324 KB Output is correct
16 Correct 7 ms 14396 KB Output is correct
17 Correct 8 ms 14412 KB Output is correct
18 Correct 7 ms 14412 KB Output is correct
19 Correct 112 ms 32200 KB Output is correct
20 Correct 124 ms 32284 KB Output is correct
21 Correct 110 ms 32096 KB Output is correct
22 Correct 122 ms 31816 KB Output is correct
23 Correct 152 ms 41344 KB Output is correct
24 Correct 127 ms 34440 KB Output is correct
25 Correct 89 ms 34244 KB Output is correct
26 Correct 59 ms 41864 KB Output is correct
27 Correct 196 ms 41468 KB Output is correct
28 Correct 264 ms 79208 KB Output is correct
29 Correct 263 ms 77304 KB Output is correct
30 Correct 192 ms 41540 KB Output is correct
31 Correct 184 ms 41640 KB Output is correct
32 Correct 238 ms 41668 KB Output is correct
33 Correct 220 ms 44940 KB Output is correct
34 Correct 315 ms 69992 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 14412 KB Output is correct
2 Correct 7 ms 14324 KB Output is correct
3 Correct 7 ms 14376 KB Output is correct
4 Correct 8 ms 14412 KB Output is correct
5 Correct 8 ms 14424 KB Output is correct
6 Correct 7 ms 14412 KB Output is correct
7 Correct 7 ms 14420 KB Output is correct
8 Correct 7 ms 14412 KB Output is correct
9 Correct 7 ms 14340 KB Output is correct
10 Correct 7 ms 14392 KB Output is correct
11 Correct 7 ms 14412 KB Output is correct
12 Correct 7 ms 14412 KB Output is correct
13 Correct 8 ms 14384 KB Output is correct
14 Correct 7 ms 14412 KB Output is correct
15 Correct 7 ms 14324 KB Output is correct
16 Correct 7 ms 14396 KB Output is correct
17 Correct 8 ms 14412 KB Output is correct
18 Correct 7 ms 14412 KB Output is correct
19 Correct 8 ms 14284 KB Output is correct
20 Correct 7 ms 14412 KB Output is correct
21 Correct 8 ms 14516 KB Output is correct
22 Correct 9 ms 14532 KB Output is correct
23 Correct 9 ms 14540 KB Output is correct
24 Correct 9 ms 14532 KB Output is correct
25 Correct 11 ms 14532 KB Output is correct
26 Correct 11 ms 14540 KB Output is correct
27 Correct 8 ms 14540 KB Output is correct
28 Correct 9 ms 14540 KB Output is correct
29 Correct 10 ms 14596 KB Output is correct
30 Correct 8 ms 14540 KB Output is correct
31 Correct 8 ms 14536 KB Output is correct
32 Correct 8 ms 14540 KB Output is correct
33 Correct 8 ms 14660 KB Output is correct
34 Correct 9 ms 14532 KB Output is correct
35 Correct 8 ms 14524 KB Output is correct
36 Correct 8 ms 14548 KB Output is correct
37 Correct 8 ms 14528 KB Output is correct
38 Correct 8 ms 14588 KB Output is correct
39 Correct 112 ms 32200 KB Output is correct
40 Correct 124 ms 32284 KB Output is correct
41 Correct 110 ms 32096 KB Output is correct
42 Correct 122 ms 31816 KB Output is correct
43 Correct 152 ms 41344 KB Output is correct
44 Correct 127 ms 34440 KB Output is correct
45 Correct 89 ms 34244 KB Output is correct
46 Correct 59 ms 41864 KB Output is correct
47 Correct 196 ms 41468 KB Output is correct
48 Correct 264 ms 79208 KB Output is correct
49 Correct 263 ms 77304 KB Output is correct
50 Correct 192 ms 41540 KB Output is correct
51 Correct 184 ms 41640 KB Output is correct
52 Correct 238 ms 41668 KB Output is correct
53 Correct 220 ms 44940 KB Output is correct
54 Correct 315 ms 69992 KB Output is correct
55 Correct 21 ms 16832 KB Output is correct
56 Correct 15 ms 15948 KB Output is correct
57 Correct 75 ms 30320 KB Output is correct
58 Correct 49 ms 25224 KB Output is correct
59 Correct 85 ms 46552 KB Output is correct
60 Correct 268 ms 77928 KB Output is correct
61 Correct 219 ms 44220 KB Output is correct
62 Correct 180 ms 41580 KB Output is correct
63 Correct 232 ms 41796 KB Output is correct
64 Correct 423 ms 83084 KB Output is correct
65 Correct 415 ms 81840 KB Output is correct
66 Correct 276 ms 73240 KB Output is correct
67 Correct 165 ms 37480 KB Output is correct
68 Correct 355 ms 54644 KB Output is correct
69 Correct 366 ms 58436 KB Output is correct
70 Correct 328 ms 52840 KB Output is correct