Submission #1088561

# Submission time Handle Problem Language Result Execution time Memory
1088561 2024-09-14T15:31:30 Z LucasLe Race (IOI11_race) C++17
31 / 100
259 ms 48704 KB
#include "race.h"
#include <bits/stdc++.h>

#define              moony  long long
#define                pii  pair<int, int>
#define                 fi  first
#define                 se  second
#define                 ld  long double
#define                 vi  vector<int>
#define                vii  vector<vector<int>>
#define             all(v)  (v).begin(), (v).end()
#define       rep(i, a, b)  for (int i = (a), _b = (b); i <= _b; ++i)
#define       per(i, b, a)  for (int i = (b), _a = (a); i >= _a; --i)

using namespace std;

const int MOD = 1e9 + 7;

int add(int a, int b) {
  a += b;
  if (a >= MOD) a -= MOD;
  return a;
}

int mul(int a, int b) {
  (a *= b) %= MOD;
  return a;
}

int ceil(int x, int y) {
  return (x + y - 1) / y;
}

int bin_pow(int x, int y) {
  int res=1;
  while(y){if(y&1)res=res*x%MOD;x=x*x%MOD;y>>=1;}
  return res;
}

const int INF = 1e9;
const int maxn = 1e6 + 5;

int n, k, ans, mx;
int sz[maxn + 5], d[maxn + 5];
bool vis[maxn + 5];
vector<pair<int, int>> g[maxn + 5];

void count_child(int u, int p) {
  sz[u] = 1;
  for (auto [v, c] : g[u]) {
    if (v == p || vis[v]) continue;
    count_child(v, u);
    sz[u] += sz[v];
  }
}

int find_centroid(int u, int p, int m) {
  for (auto [v, c] : g[u]) {
    if (v == p || vis[v]) continue;
    if (sz[v] > m / 2) return find_centroid(v, u, m);
  }
  return u;
}

void dfs(int u, int p, int sum, int h, bool status) {
  if (sum <= k) {
    if (!status) {
      ans = min(ans, h + d[k - sum]);
    } else {
      d[sum] = min(d[sum], h);
    }
    mx = max(mx, sum);
  }
  for (auto [v, cost] : g[u]) {
    if (v == p || vis[v]) continue;
    dfs(v, u, min(sum + cost, k + 1), h + 1, status);
  }
}

int CT(int u) {
  count_child(u, 0);
  int m = sz[u];
  int c = find_centroid(u, 0, m);
  vis[c] = true;
  d[0] = 0; mx = 0;
  for (auto [v, cost] : g[c]) {
    if (vis[v]) continue;
    dfs(v, c, cost, 1, false);
    dfs(v, c, cost, 1, true);
  }
  fill(d, d + mx + 1, INF);
  for (auto [v, cost] : g[c]) {
    if (vis[v]) continue;
    CT(v);
  }
  return c;
}

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];
    int v = H[i][1];
    int c = L[i];
    g[u].push_back({v, c});
    g[v].push_back({u, c});
  }
  fill(d, d + n + 1, INF);
  ans = INF;
  CT(1);
  return (ans == INF ? -1 : ans);
}
# Verdict Execution time Memory Grader output
1 Correct 11 ms 23896 KB Output is correct
2 Correct 10 ms 23900 KB Output is correct
3 Correct 14 ms 23864 KB Output is correct
4 Correct 10 ms 23900 KB Output is correct
5 Correct 10 ms 23900 KB Output is correct
6 Correct 11 ms 23964 KB Output is correct
7 Correct 11 ms 23900 KB Output is correct
8 Correct 11 ms 23900 KB Output is correct
9 Correct 10 ms 23900 KB Output is correct
10 Correct 10 ms 23900 KB Output is correct
11 Correct 10 ms 23900 KB Output is correct
12 Correct 10 ms 23900 KB Output is correct
13 Correct 10 ms 23836 KB Output is correct
14 Correct 10 ms 23900 KB Output is correct
15 Correct 10 ms 23900 KB Output is correct
16 Correct 10 ms 23896 KB Output is correct
17 Correct 11 ms 23900 KB Output is correct
18 Correct 12 ms 23732 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 23896 KB Output is correct
2 Correct 10 ms 23900 KB Output is correct
3 Correct 14 ms 23864 KB Output is correct
4 Correct 10 ms 23900 KB Output is correct
5 Correct 10 ms 23900 KB Output is correct
6 Correct 11 ms 23964 KB Output is correct
7 Correct 11 ms 23900 KB Output is correct
8 Correct 11 ms 23900 KB Output is correct
9 Correct 10 ms 23900 KB Output is correct
10 Correct 10 ms 23900 KB Output is correct
11 Correct 10 ms 23900 KB Output is correct
12 Correct 10 ms 23900 KB Output is correct
13 Correct 10 ms 23836 KB Output is correct
14 Correct 10 ms 23900 KB Output is correct
15 Correct 10 ms 23900 KB Output is correct
16 Correct 10 ms 23896 KB Output is correct
17 Correct 11 ms 23900 KB Output is correct
18 Correct 12 ms 23732 KB Output is correct
19 Correct 10 ms 23896 KB Output is correct
20 Correct 10 ms 23928 KB Output is correct
21 Correct 10 ms 23896 KB Output is correct
22 Incorrect 112 ms 27596 KB Output isn't correct
23 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 11 ms 23896 KB Output is correct
2 Correct 10 ms 23900 KB Output is correct
3 Correct 14 ms 23864 KB Output is correct
4 Correct 10 ms 23900 KB Output is correct
5 Correct 10 ms 23900 KB Output is correct
6 Correct 11 ms 23964 KB Output is correct
7 Correct 11 ms 23900 KB Output is correct
8 Correct 11 ms 23900 KB Output is correct
9 Correct 10 ms 23900 KB Output is correct
10 Correct 10 ms 23900 KB Output is correct
11 Correct 10 ms 23900 KB Output is correct
12 Correct 10 ms 23900 KB Output is correct
13 Correct 10 ms 23836 KB Output is correct
14 Correct 10 ms 23900 KB Output is correct
15 Correct 10 ms 23900 KB Output is correct
16 Correct 10 ms 23896 KB Output is correct
17 Correct 11 ms 23900 KB Output is correct
18 Correct 12 ms 23732 KB Output is correct
19 Correct 97 ms 29520 KB Output is correct
20 Correct 97 ms 29528 KB Output is correct
21 Correct 92 ms 29520 KB Output is correct
22 Correct 80 ms 29524 KB Output is correct
23 Correct 76 ms 29836 KB Output is correct
24 Correct 50 ms 29564 KB Output is correct
25 Correct 122 ms 36432 KB Output is correct
26 Correct 67 ms 36944 KB Output is correct
27 Correct 130 ms 35408 KB Output is correct
28 Correct 259 ms 48704 KB Output is correct
29 Correct 246 ms 43604 KB Output is correct
30 Correct 120 ms 35520 KB Output is correct
31 Correct 122 ms 35408 KB Output is correct
32 Correct 130 ms 35408 KB Output is correct
33 Correct 176 ms 34356 KB Output is correct
34 Correct 179 ms 34388 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 23896 KB Output is correct
2 Correct 10 ms 23900 KB Output is correct
3 Correct 14 ms 23864 KB Output is correct
4 Correct 10 ms 23900 KB Output is correct
5 Correct 10 ms 23900 KB Output is correct
6 Correct 11 ms 23964 KB Output is correct
7 Correct 11 ms 23900 KB Output is correct
8 Correct 11 ms 23900 KB Output is correct
9 Correct 10 ms 23900 KB Output is correct
10 Correct 10 ms 23900 KB Output is correct
11 Correct 10 ms 23900 KB Output is correct
12 Correct 10 ms 23900 KB Output is correct
13 Correct 10 ms 23836 KB Output is correct
14 Correct 10 ms 23900 KB Output is correct
15 Correct 10 ms 23900 KB Output is correct
16 Correct 10 ms 23896 KB Output is correct
17 Correct 11 ms 23900 KB Output is correct
18 Correct 12 ms 23732 KB Output is correct
19 Correct 10 ms 23896 KB Output is correct
20 Correct 10 ms 23928 KB Output is correct
21 Correct 10 ms 23896 KB Output is correct
22 Incorrect 112 ms 27596 KB Output isn't correct
23 Halted 0 ms 0 KB -