Submission #1096000

# Submission time Handle Problem Language Result Execution time Memory
1096000 2024-10-03T14:31:47 Z YugiHacker Race (IOI11_race) C++17
100 / 100
301 ms 37824 KB
#ifndef yugi
#include "race.h"
#endif // yugi

#define maxn 200005
#define maxk 1000006
#include<bits/stdc++.h>
using namespace std;
int n, k, sz[maxn], del[maxn], mi[maxk];
vector <int> rollback;
vector <pair<int, int>> a[maxn];
void dfs(int u, int p) {
    sz[u] = 1;
    for (auto [v, w] : a[u]) if (v != p && !del[v]) dfs(v, u), sz[u] += sz[v];
}
int centroid(int u, int p, int cnt) {
    for (auto [v, w] : a[u]) if (v != p && !del[v] && sz[v] * 2 > cnt) return centroid(v, u, cnt);
    return u;
}
int ans = 1e9;
void query(int u, int p, int d, int len, int op) {
    if (len > k) return;
    if (op == 0) ans = min(ans, d + mi[k - len]);
    else {
        mi[len] = min(mi[len], d);
        rollback.push_back(len);
    }
    for (auto [v, w] : a[u]) if (v != p && !del[v])
        query(v, u, d+1, len+w, op);
}
void CentroidDecomposition(int u) {
    dfs(u, -1);
    int cen = centroid(u, -1, sz[u]);
    del[cen] = 1;

    mi[0] = 0;
    for (auto [v, w] : a[cen]) if (!del[v]) {
        query(v, cen, 1, w, 0);
        query(v, cen, 1, w, 1);
    }
    for (int x:rollback) mi[x] = 1e9;
    rollback.clear();

    for (auto [v, w] : a[cen]) if (!del[v])
        CentroidDecomposition(v);
}
int best_path(int N, int K, int H[][2], int L[])
{
  n = N, k = K;
  for (int i=0; i<n-1; i++)
  {
      int u = H[i][0], v = H[i][1], w = L[i];
      a[u].push_back({v, w});
      a[v].push_back({u, w});
  }
  for (int i=1; i<=1e6; i++) mi[i] = 1e9;
  CentroidDecomposition(0);
  if (ans > n) ans = -1;
  return ans;
}

#ifdef yugi
main() {
    int n, k; cin >> n >> k;
    int h[n+1][2], l[n+1];
    for (int i=0; i<n-1; i++) {
        cin >> h[i][0] >> h[i][1] >> l[i];
    }
    cout << best_path(n, k, h, l);
}
#endif // yugi
# Verdict Execution time Memory Grader output
1 Correct 4 ms 9048 KB Output is correct
2 Correct 4 ms 9048 KB Output is correct
3 Correct 4 ms 9048 KB Output is correct
4 Correct 4 ms 9052 KB Output is correct
5 Correct 4 ms 8836 KB Output is correct
6 Correct 6 ms 9052 KB Output is correct
7 Correct 4 ms 9052 KB Output is correct
8 Correct 4 ms 9052 KB Output is correct
9 Correct 5 ms 8988 KB Output is correct
10 Correct 4 ms 9092 KB Output is correct
11 Correct 4 ms 9052 KB Output is correct
12 Correct 3 ms 9052 KB Output is correct
13 Correct 4 ms 9048 KB Output is correct
14 Correct 4 ms 9052 KB Output is correct
15 Correct 4 ms 9052 KB Output is correct
16 Correct 4 ms 9052 KB Output is correct
17 Correct 4 ms 9080 KB Output is correct
18 Correct 4 ms 9004 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 9048 KB Output is correct
2 Correct 4 ms 9048 KB Output is correct
3 Correct 4 ms 9048 KB Output is correct
4 Correct 4 ms 9052 KB Output is correct
5 Correct 4 ms 8836 KB Output is correct
6 Correct 6 ms 9052 KB Output is correct
7 Correct 4 ms 9052 KB Output is correct
8 Correct 4 ms 9052 KB Output is correct
9 Correct 5 ms 8988 KB Output is correct
10 Correct 4 ms 9092 KB Output is correct
11 Correct 4 ms 9052 KB Output is correct
12 Correct 3 ms 9052 KB Output is correct
13 Correct 4 ms 9048 KB Output is correct
14 Correct 4 ms 9052 KB Output is correct
15 Correct 4 ms 9052 KB Output is correct
16 Correct 4 ms 9052 KB Output is correct
17 Correct 4 ms 9080 KB Output is correct
18 Correct 4 ms 9004 KB Output is correct
19 Correct 5 ms 9052 KB Output is correct
20 Correct 4 ms 8988 KB Output is correct
21 Correct 5 ms 9052 KB Output is correct
22 Correct 5 ms 9304 KB Output is correct
23 Correct 5 ms 9052 KB Output is correct
24 Correct 5 ms 9104 KB Output is correct
25 Correct 5 ms 9048 KB Output is correct
26 Correct 5 ms 9048 KB Output is correct
27 Correct 4 ms 9052 KB Output is correct
28 Correct 5 ms 9052 KB Output is correct
29 Correct 4 ms 9052 KB Output is correct
30 Correct 5 ms 9052 KB Output is correct
31 Correct 5 ms 9052 KB Output is correct
32 Correct 5 ms 9052 KB Output is correct
33 Correct 5 ms 9052 KB Output is correct
34 Correct 5 ms 9152 KB Output is correct
35 Correct 5 ms 9048 KB Output is correct
36 Correct 6 ms 9052 KB Output is correct
37 Correct 5 ms 9052 KB Output is correct
38 Correct 5 ms 8932 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 9048 KB Output is correct
2 Correct 4 ms 9048 KB Output is correct
3 Correct 4 ms 9048 KB Output is correct
4 Correct 4 ms 9052 KB Output is correct
5 Correct 4 ms 8836 KB Output is correct
6 Correct 6 ms 9052 KB Output is correct
7 Correct 4 ms 9052 KB Output is correct
8 Correct 4 ms 9052 KB Output is correct
9 Correct 5 ms 8988 KB Output is correct
10 Correct 4 ms 9092 KB Output is correct
11 Correct 4 ms 9052 KB Output is correct
12 Correct 3 ms 9052 KB Output is correct
13 Correct 4 ms 9048 KB Output is correct
14 Correct 4 ms 9052 KB Output is correct
15 Correct 4 ms 9052 KB Output is correct
16 Correct 4 ms 9052 KB Output is correct
17 Correct 4 ms 9080 KB Output is correct
18 Correct 4 ms 9004 KB Output is correct
19 Correct 91 ms 16124 KB Output is correct
20 Correct 79 ms 15944 KB Output is correct
21 Correct 87 ms 16184 KB Output is correct
22 Correct 72 ms 16588 KB Output is correct
23 Correct 45 ms 16232 KB Output is correct
24 Correct 35 ms 16220 KB Output is correct
25 Correct 86 ms 19504 KB Output is correct
26 Correct 66 ms 23768 KB Output is correct
27 Correct 97 ms 23376 KB Output is correct
28 Correct 155 ms 37716 KB Output is correct
29 Correct 162 ms 36688 KB Output is correct
30 Correct 89 ms 23376 KB Output is correct
31 Correct 93 ms 23316 KB Output is correct
32 Correct 114 ms 23560 KB Output is correct
33 Correct 135 ms 22100 KB Output is correct
34 Correct 118 ms 23124 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 9048 KB Output is correct
2 Correct 4 ms 9048 KB Output is correct
3 Correct 4 ms 9048 KB Output is correct
4 Correct 4 ms 9052 KB Output is correct
5 Correct 4 ms 8836 KB Output is correct
6 Correct 6 ms 9052 KB Output is correct
7 Correct 4 ms 9052 KB Output is correct
8 Correct 4 ms 9052 KB Output is correct
9 Correct 5 ms 8988 KB Output is correct
10 Correct 4 ms 9092 KB Output is correct
11 Correct 4 ms 9052 KB Output is correct
12 Correct 3 ms 9052 KB Output is correct
13 Correct 4 ms 9048 KB Output is correct
14 Correct 4 ms 9052 KB Output is correct
15 Correct 4 ms 9052 KB Output is correct
16 Correct 4 ms 9052 KB Output is correct
17 Correct 4 ms 9080 KB Output is correct
18 Correct 4 ms 9004 KB Output is correct
19 Correct 5 ms 9052 KB Output is correct
20 Correct 4 ms 8988 KB Output is correct
21 Correct 5 ms 9052 KB Output is correct
22 Correct 5 ms 9304 KB Output is correct
23 Correct 5 ms 9052 KB Output is correct
24 Correct 5 ms 9104 KB Output is correct
25 Correct 5 ms 9048 KB Output is correct
26 Correct 5 ms 9048 KB Output is correct
27 Correct 4 ms 9052 KB Output is correct
28 Correct 5 ms 9052 KB Output is correct
29 Correct 4 ms 9052 KB Output is correct
30 Correct 5 ms 9052 KB Output is correct
31 Correct 5 ms 9052 KB Output is correct
32 Correct 5 ms 9052 KB Output is correct
33 Correct 5 ms 9052 KB Output is correct
34 Correct 5 ms 9152 KB Output is correct
35 Correct 5 ms 9048 KB Output is correct
36 Correct 6 ms 9052 KB Output is correct
37 Correct 5 ms 9052 KB Output is correct
38 Correct 5 ms 8932 KB Output is correct
39 Correct 91 ms 16124 KB Output is correct
40 Correct 79 ms 15944 KB Output is correct
41 Correct 87 ms 16184 KB Output is correct
42 Correct 72 ms 16588 KB Output is correct
43 Correct 45 ms 16232 KB Output is correct
44 Correct 35 ms 16220 KB Output is correct
45 Correct 86 ms 19504 KB Output is correct
46 Correct 66 ms 23768 KB Output is correct
47 Correct 97 ms 23376 KB Output is correct
48 Correct 155 ms 37716 KB Output is correct
49 Correct 162 ms 36688 KB Output is correct
50 Correct 89 ms 23376 KB Output is correct
51 Correct 93 ms 23316 KB Output is correct
52 Correct 114 ms 23560 KB Output is correct
53 Correct 135 ms 22100 KB Output is correct
54 Correct 118 ms 23124 KB Output is correct
55 Correct 9 ms 9816 KB Output is correct
56 Correct 11 ms 9820 KB Output is correct
57 Correct 46 ms 16588 KB Output is correct
58 Correct 32 ms 16840 KB Output is correct
59 Correct 72 ms 23760 KB Output is correct
60 Correct 301 ms 37824 KB Output is correct
61 Correct 110 ms 23764 KB Output is correct
62 Correct 115 ms 24268 KB Output is correct
63 Correct 152 ms 24392 KB Output is correct
64 Correct 250 ms 24548 KB Output is correct
65 Correct 119 ms 24144 KB Output is correct
66 Correct 248 ms 34344 KB Output is correct
67 Correct 69 ms 25792 KB Output is correct
68 Correct 138 ms 24520 KB Output is correct
69 Correct 142 ms 24780 KB Output is correct
70 Correct 127 ms 24012 KB Output is correct