답안 #864067

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
864067 2023-10-21T20:08:08 Z blackslex 경주 (Race) (IOI11_race) C++17
100 / 100
343 ms 111928 KB
#include "race.h"
#include<bits/stdc++.h>

using namespace std;
using ll = long long;
using pii = pair<ll, ll>;

const int MxN = 2e5 + 5, MxK = 1e6 + 5;
ll d, sz[MxN], rpar, mn[MxK], ans = 1e12;
vector<pii> v[MxN], u[MxN];
vector<ll> t;
bool f[MxN];

ll dfssz (ll cur, ll par) {
  sz[cur] = 1;
  for (auto &[x, y]: v[cur]) if (par != x && !f[x]) sz[cur] += dfssz(x, cur);
  return sz[cur];
}

ll cen (ll cur, ll par, ll now) {
  for (auto &[x, y]: v[cur]) if (par != x && !f[x] && sz[x] * 2 > now) return cen(x, cur, now);
  return cur;
}

void dfs (ll cur, ll par, ll dist, ll len) {
  if (dist > d) return; u[rpar].emplace_back(dist, len); t.emplace_back(dist);
  for (auto &[x, y]: v[cur]) if (par != x && !f[x]) dfs(x, cur, dist + y, len + 1);
}

void upd (ll cur) {
  for (auto &[x, y]: u[cur]) if (x <= d && mn[d - x] != 1e12) ans = min(ans, mn[d - x] + y);
  for (auto &[x, y]: u[cur]) mn[x] = min(mn[x], y);
}

void decom (ll cur) {
  cur = cen(cur, 0, dfssz(cur, 0)); f[cur] = 1; mn[0] = 0;
  for (auto &[x, y]: v[cur]) if (!f[x]) rpar = x, dfs(x, 0, y, 1), upd(x);
  for (auto &e: t) mn[e] = 1e12; t.clear();
  for (auto &[x, y]: v[cur]) if (!f[x]) u[x].clear();
  for (auto &[x, y]: v[cur]) if (!f[x]) decom(x);
}

int best_path(int n, int K, int h[][2], int l[]) {
  d = K;
  for (int i = 0; i < MxK; i++) mn[i] = 1e12;
  for (int i = 0; i < n - 1; i++) h[i][0]++, h[i][1]++;
  for (int i = 0; i < n - 1; i++) v[h[i][0]].emplace_back(h[i][1], l[i]), v[h[i][1]].emplace_back(h[i][0], l[i]);
  decom(1);
  return (ans == 1e12 ? -1 : ans);
}

Compilation message

race.cpp: In function 'void dfs(ll, ll, ll, ll)':
race.cpp:26:3: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
   26 |   if (dist > d) return; u[rpar].emplace_back(dist, len); t.emplace_back(dist);
      |   ^~
race.cpp:26:25: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
   26 |   if (dist > d) return; u[rpar].emplace_back(dist, len); t.emplace_back(dist);
      |                         ^
race.cpp: In function 'void decom(ll)':
race.cpp:38:3: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
   38 |   for (auto &e: t) mn[e] = 1e12; t.clear();
      |   ^~~
race.cpp:38:34: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
   38 |   for (auto &e: t) mn[e] = 1e12; t.clear();
      |                                  ^
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 23128 KB Output is correct
2 Correct 4 ms 22872 KB Output is correct
3 Correct 4 ms 22872 KB Output is correct
4 Correct 4 ms 22876 KB Output is correct
5 Correct 4 ms 22876 KB Output is correct
6 Correct 4 ms 22876 KB Output is correct
7 Correct 4 ms 23132 KB Output is correct
8 Correct 4 ms 23016 KB Output is correct
9 Correct 4 ms 22876 KB Output is correct
10 Correct 4 ms 22876 KB Output is correct
11 Correct 4 ms 22876 KB Output is correct
12 Correct 4 ms 23012 KB Output is correct
13 Correct 4 ms 22876 KB Output is correct
14 Correct 4 ms 23032 KB Output is correct
15 Correct 4 ms 22876 KB Output is correct
16 Correct 5 ms 23132 KB Output is correct
17 Correct 4 ms 22876 KB Output is correct
18 Correct 4 ms 22876 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 23128 KB Output is correct
2 Correct 4 ms 22872 KB Output is correct
3 Correct 4 ms 22872 KB Output is correct
4 Correct 4 ms 22876 KB Output is correct
5 Correct 4 ms 22876 KB Output is correct
6 Correct 4 ms 22876 KB Output is correct
7 Correct 4 ms 23132 KB Output is correct
8 Correct 4 ms 23016 KB Output is correct
9 Correct 4 ms 22876 KB Output is correct
10 Correct 4 ms 22876 KB Output is correct
11 Correct 4 ms 22876 KB Output is correct
12 Correct 4 ms 23012 KB Output is correct
13 Correct 4 ms 22876 KB Output is correct
14 Correct 4 ms 23032 KB Output is correct
15 Correct 4 ms 22876 KB Output is correct
16 Correct 5 ms 23132 KB Output is correct
17 Correct 4 ms 22876 KB Output is correct
18 Correct 4 ms 22876 KB Output is correct
19 Correct 4 ms 22872 KB Output is correct
20 Correct 4 ms 22876 KB Output is correct
21 Correct 4 ms 23132 KB Output is correct
22 Correct 4 ms 23008 KB Output is correct
23 Correct 4 ms 22876 KB Output is correct
24 Correct 4 ms 22876 KB Output is correct
25 Correct 4 ms 23128 KB Output is correct
26 Correct 4 ms 22876 KB Output is correct
27 Correct 4 ms 22876 KB Output is correct
28 Correct 5 ms 23132 KB Output is correct
29 Correct 5 ms 23132 KB Output is correct
30 Correct 5 ms 23132 KB Output is correct
31 Correct 5 ms 23132 KB Output is correct
32 Correct 5 ms 23132 KB Output is correct
33 Correct 5 ms 23132 KB Output is correct
34 Correct 5 ms 23132 KB Output is correct
35 Correct 4 ms 23132 KB Output is correct
36 Correct 4 ms 23072 KB Output is correct
37 Correct 4 ms 23132 KB Output is correct
38 Correct 4 ms 23132 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 23128 KB Output is correct
2 Correct 4 ms 22872 KB Output is correct
3 Correct 4 ms 22872 KB Output is correct
4 Correct 4 ms 22876 KB Output is correct
5 Correct 4 ms 22876 KB Output is correct
6 Correct 4 ms 22876 KB Output is correct
7 Correct 4 ms 23132 KB Output is correct
8 Correct 4 ms 23016 KB Output is correct
9 Correct 4 ms 22876 KB Output is correct
10 Correct 4 ms 22876 KB Output is correct
11 Correct 4 ms 22876 KB Output is correct
12 Correct 4 ms 23012 KB Output is correct
13 Correct 4 ms 22876 KB Output is correct
14 Correct 4 ms 23032 KB Output is correct
15 Correct 4 ms 22876 KB Output is correct
16 Correct 5 ms 23132 KB Output is correct
17 Correct 4 ms 22876 KB Output is correct
18 Correct 4 ms 22876 KB Output is correct
19 Correct 90 ms 44884 KB Output is correct
20 Correct 94 ms 45648 KB Output is correct
21 Correct 106 ms 48000 KB Output is correct
22 Correct 87 ms 46316 KB Output is correct
23 Correct 59 ms 36688 KB Output is correct
24 Correct 47 ms 35872 KB Output is correct
25 Correct 97 ms 55124 KB Output is correct
26 Correct 96 ms 67084 KB Output is correct
27 Correct 131 ms 50260 KB Output is correct
28 Correct 177 ms 55636 KB Output is correct
29 Correct 208 ms 54612 KB Output is correct
30 Correct 131 ms 50260 KB Output is correct
31 Correct 127 ms 50088 KB Output is correct
32 Correct 149 ms 48484 KB Output is correct
33 Correct 164 ms 65364 KB Output is correct
34 Correct 117 ms 38664 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 23128 KB Output is correct
2 Correct 4 ms 22872 KB Output is correct
3 Correct 4 ms 22872 KB Output is correct
4 Correct 4 ms 22876 KB Output is correct
5 Correct 4 ms 22876 KB Output is correct
6 Correct 4 ms 22876 KB Output is correct
7 Correct 4 ms 23132 KB Output is correct
8 Correct 4 ms 23016 KB Output is correct
9 Correct 4 ms 22876 KB Output is correct
10 Correct 4 ms 22876 KB Output is correct
11 Correct 4 ms 22876 KB Output is correct
12 Correct 4 ms 23012 KB Output is correct
13 Correct 4 ms 22876 KB Output is correct
14 Correct 4 ms 23032 KB Output is correct
15 Correct 4 ms 22876 KB Output is correct
16 Correct 5 ms 23132 KB Output is correct
17 Correct 4 ms 22876 KB Output is correct
18 Correct 4 ms 22876 KB Output is correct
19 Correct 4 ms 22872 KB Output is correct
20 Correct 4 ms 22876 KB Output is correct
21 Correct 4 ms 23132 KB Output is correct
22 Correct 4 ms 23008 KB Output is correct
23 Correct 4 ms 22876 KB Output is correct
24 Correct 4 ms 22876 KB Output is correct
25 Correct 4 ms 23128 KB Output is correct
26 Correct 4 ms 22876 KB Output is correct
27 Correct 4 ms 22876 KB Output is correct
28 Correct 5 ms 23132 KB Output is correct
29 Correct 5 ms 23132 KB Output is correct
30 Correct 5 ms 23132 KB Output is correct
31 Correct 5 ms 23132 KB Output is correct
32 Correct 5 ms 23132 KB Output is correct
33 Correct 5 ms 23132 KB Output is correct
34 Correct 5 ms 23132 KB Output is correct
35 Correct 4 ms 23132 KB Output is correct
36 Correct 4 ms 23072 KB Output is correct
37 Correct 4 ms 23132 KB Output is correct
38 Correct 4 ms 23132 KB Output is correct
39 Correct 90 ms 44884 KB Output is correct
40 Correct 94 ms 45648 KB Output is correct
41 Correct 106 ms 48000 KB Output is correct
42 Correct 87 ms 46316 KB Output is correct
43 Correct 59 ms 36688 KB Output is correct
44 Correct 47 ms 35872 KB Output is correct
45 Correct 97 ms 55124 KB Output is correct
46 Correct 96 ms 67084 KB Output is correct
47 Correct 131 ms 50260 KB Output is correct
48 Correct 177 ms 55636 KB Output is correct
49 Correct 208 ms 54612 KB Output is correct
50 Correct 131 ms 50260 KB Output is correct
51 Correct 127 ms 50088 KB Output is correct
52 Correct 149 ms 48484 KB Output is correct
53 Correct 164 ms 65364 KB Output is correct
54 Correct 117 ms 38664 KB Output is correct
55 Correct 10 ms 24668 KB Output is correct
56 Correct 12 ms 25180 KB Output is correct
57 Correct 74 ms 56536 KB Output is correct
58 Correct 34 ms 34756 KB Output is correct
59 Correct 84 ms 66876 KB Output is correct
60 Correct 314 ms 111928 KB Output is correct
61 Correct 177 ms 56776 KB Output is correct
62 Correct 146 ms 63424 KB Output is correct
63 Correct 185 ms 63588 KB Output is correct
64 Correct 343 ms 80292 KB Output is correct
65 Correct 124 ms 39420 KB Output is correct
66 Correct 308 ms 92156 KB Output is correct
67 Correct 100 ms 46524 KB Output is correct
68 Correct 176 ms 58264 KB Output is correct
69 Correct 187 ms 57928 KB Output is correct
70 Correct 166 ms 56396 KB Output is correct