답안 #1116975

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1116975 2024-11-22T16:59:53 Z repmann 경주 (Race) (IOI11_race) C++14
100 / 100
290 ms 32484 KB
#include <bits/stdc++.h>
using namespace std;
int N, K, sol = INT_MAX;
int SIZE[200006], DP[200006], W[200006], D[1000006];
bool V[200006];
vector <pair <int, int>> VG[200006];
inline void SDFS(int node, int parent = -1)
{
  SIZE[node] = 1;
  for(pair <int, int> p : VG[node])
  {
    if((p.second == parent) || V[p.second]) continue;
    SDFS(p.second, node);
    SIZE[node] += SIZE[p.second];
  }
  return;
}
inline int CDFS(int node, int n, int parent = -1)
{
  for(pair <int, int> p : VG[node])
  {
    if((p.second == parent) || V[p.second]) continue;
    if(SIZE[p.second] > n) return CDFS(p.second, n, node);
  }
  return node;
}
inline void DFS1(int node, int parent = -1)
{
  if(W[node] > K) return;
  if(D[K - W[node]] != INT_MAX) sol = min(DP[node] + D[K - W[node]], sol);
  for(pair <int, int> p : VG[node])
  {
    if((p.second == parent) || V[p.second]) continue;
    DP[p.second] = DP[node] + 1;
    W[p.second] = W[node] + p.first;
    DFS1(p.second, node);
  }
  return;
}
inline void DFS2(int node, int parent = -1)
{
  if(W[node] > K) return;
  D[W[node]] = min(DP[node], D[W[node]]);
  for(pair <int, int> p : VG[node])
  {
    if((p.second == parent) || V[p.second]) continue;
    DFS2(p.second, node);
  }
  return;
}
inline void CLEARDFS(int node, int parent = -1)
{
  if(W[node] > K) return;
  D[W[node]] = INT_MAX;
  for(pair <int, int> p : VG[node])
  {
    if((p.second == parent) || V[p.second]) continue;
    CLEARDFS(p.second, node);
  }
  return;
}
inline void CD(int root)
{
  SDFS(root);
  int centroid = CDFS(root, SIZE[root] >> 1);
  V[centroid] = true;
  D[0] = 0;
  for(pair <int, int> p : VG[centroid])
  {
    if(V[p.second]) continue;
    DP[p.second] = 1;
    W[p.second] = p.first;
    DFS1(p.second, centroid);
    DFS2(p.second, centroid);
  }
  W[centroid] = 0;
  CLEARDFS(centroid);
  for(pair <int, int> p : VG[centroid]) if(!V[p.second]) CD(p.second);
}
int best_path(int n, int k, int (*H)[2], int* L)
{
  N = n;
  K = k;
  for(int i = 0; i < N - 1; i++)
  {
    VG[H[i][0] + 1].push_back({L[i], H[i][1] + 1});
    VG[H[i][1] + 1].push_back({L[i], H[i][0] + 1});
  }
  for(int i = 0; i <= K; i++) D[i] = INT_MAX;
  CD(1);
  if(sol == INT_MAX) return -1;
  return sol;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 12624 KB Output is correct
2 Correct 2 ms 12624 KB Output is correct
3 Correct 3 ms 12624 KB Output is correct
4 Correct 2 ms 12624 KB Output is correct
5 Correct 2 ms 12624 KB Output is correct
6 Correct 2 ms 12624 KB Output is correct
7 Correct 2 ms 12624 KB Output is correct
8 Correct 3 ms 12624 KB Output is correct
9 Correct 3 ms 12752 KB Output is correct
10 Correct 3 ms 12636 KB Output is correct
11 Correct 3 ms 12880 KB Output is correct
12 Correct 3 ms 12624 KB Output is correct
13 Correct 3 ms 12624 KB Output is correct
14 Correct 2 ms 12624 KB Output is correct
15 Correct 3 ms 12624 KB Output is correct
16 Correct 3 ms 12624 KB Output is correct
17 Correct 3 ms 12792 KB Output is correct
18 Correct 3 ms 12624 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 12624 KB Output is correct
2 Correct 2 ms 12624 KB Output is correct
3 Correct 3 ms 12624 KB Output is correct
4 Correct 2 ms 12624 KB Output is correct
5 Correct 2 ms 12624 KB Output is correct
6 Correct 2 ms 12624 KB Output is correct
7 Correct 2 ms 12624 KB Output is correct
8 Correct 3 ms 12624 KB Output is correct
9 Correct 3 ms 12752 KB Output is correct
10 Correct 3 ms 12636 KB Output is correct
11 Correct 3 ms 12880 KB Output is correct
12 Correct 3 ms 12624 KB Output is correct
13 Correct 3 ms 12624 KB Output is correct
14 Correct 2 ms 12624 KB Output is correct
15 Correct 3 ms 12624 KB Output is correct
16 Correct 3 ms 12624 KB Output is correct
17 Correct 3 ms 12792 KB Output is correct
18 Correct 3 ms 12624 KB Output is correct
19 Correct 2 ms 12800 KB Output is correct
20 Correct 3 ms 12624 KB Output is correct
21 Correct 3 ms 12624 KB Output is correct
22 Correct 5 ms 14672 KB Output is correct
23 Correct 3 ms 14672 KB Output is correct
24 Correct 4 ms 14824 KB Output is correct
25 Correct 4 ms 14672 KB Output is correct
26 Correct 3 ms 12796 KB Output is correct
27 Correct 5 ms 14672 KB Output is correct
28 Correct 3 ms 12768 KB Output is correct
29 Correct 3 ms 12624 KB Output is correct
30 Correct 3 ms 12624 KB Output is correct
31 Correct 4 ms 14672 KB Output is correct
32 Correct 4 ms 14672 KB Output is correct
33 Correct 3 ms 14672 KB Output is correct
34 Correct 3 ms 14672 KB Output is correct
35 Correct 3 ms 14672 KB Output is correct
36 Correct 3 ms 14672 KB Output is correct
37 Correct 3 ms 14672 KB Output is correct
38 Correct 3 ms 14672 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 12624 KB Output is correct
2 Correct 2 ms 12624 KB Output is correct
3 Correct 3 ms 12624 KB Output is correct
4 Correct 2 ms 12624 KB Output is correct
5 Correct 2 ms 12624 KB Output is correct
6 Correct 2 ms 12624 KB Output is correct
7 Correct 2 ms 12624 KB Output is correct
8 Correct 3 ms 12624 KB Output is correct
9 Correct 3 ms 12752 KB Output is correct
10 Correct 3 ms 12636 KB Output is correct
11 Correct 3 ms 12880 KB Output is correct
12 Correct 3 ms 12624 KB Output is correct
13 Correct 3 ms 12624 KB Output is correct
14 Correct 2 ms 12624 KB Output is correct
15 Correct 3 ms 12624 KB Output is correct
16 Correct 3 ms 12624 KB Output is correct
17 Correct 3 ms 12792 KB Output is correct
18 Correct 3 ms 12624 KB Output is correct
19 Correct 87 ms 19900 KB Output is correct
20 Correct 86 ms 19812 KB Output is correct
21 Correct 94 ms 20052 KB Output is correct
22 Correct 80 ms 20048 KB Output is correct
23 Correct 42 ms 20304 KB Output is correct
24 Correct 38 ms 20248 KB Output is correct
25 Correct 83 ms 21128 KB Output is correct
26 Correct 63 ms 22612 KB Output is correct
27 Correct 105 ms 25672 KB Output is correct
28 Correct 152 ms 30976 KB Output is correct
29 Correct 149 ms 30280 KB Output is correct
30 Correct 120 ms 25696 KB Output is correct
31 Correct 96 ms 25672 KB Output is correct
32 Correct 114 ms 25928 KB Output is correct
33 Correct 147 ms 24548 KB Output is correct
34 Correct 115 ms 25416 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 12624 KB Output is correct
2 Correct 2 ms 12624 KB Output is correct
3 Correct 3 ms 12624 KB Output is correct
4 Correct 2 ms 12624 KB Output is correct
5 Correct 2 ms 12624 KB Output is correct
6 Correct 2 ms 12624 KB Output is correct
7 Correct 2 ms 12624 KB Output is correct
8 Correct 3 ms 12624 KB Output is correct
9 Correct 3 ms 12752 KB Output is correct
10 Correct 3 ms 12636 KB Output is correct
11 Correct 3 ms 12880 KB Output is correct
12 Correct 3 ms 12624 KB Output is correct
13 Correct 3 ms 12624 KB Output is correct
14 Correct 2 ms 12624 KB Output is correct
15 Correct 3 ms 12624 KB Output is correct
16 Correct 3 ms 12624 KB Output is correct
17 Correct 3 ms 12792 KB Output is correct
18 Correct 3 ms 12624 KB Output is correct
19 Correct 2 ms 12800 KB Output is correct
20 Correct 3 ms 12624 KB Output is correct
21 Correct 3 ms 12624 KB Output is correct
22 Correct 5 ms 14672 KB Output is correct
23 Correct 3 ms 14672 KB Output is correct
24 Correct 4 ms 14824 KB Output is correct
25 Correct 4 ms 14672 KB Output is correct
26 Correct 3 ms 12796 KB Output is correct
27 Correct 5 ms 14672 KB Output is correct
28 Correct 3 ms 12768 KB Output is correct
29 Correct 3 ms 12624 KB Output is correct
30 Correct 3 ms 12624 KB Output is correct
31 Correct 4 ms 14672 KB Output is correct
32 Correct 4 ms 14672 KB Output is correct
33 Correct 3 ms 14672 KB Output is correct
34 Correct 3 ms 14672 KB Output is correct
35 Correct 3 ms 14672 KB Output is correct
36 Correct 3 ms 14672 KB Output is correct
37 Correct 3 ms 14672 KB Output is correct
38 Correct 3 ms 14672 KB Output is correct
39 Correct 87 ms 19900 KB Output is correct
40 Correct 86 ms 19812 KB Output is correct
41 Correct 94 ms 20052 KB Output is correct
42 Correct 80 ms 20048 KB Output is correct
43 Correct 42 ms 20304 KB Output is correct
44 Correct 38 ms 20248 KB Output is correct
45 Correct 83 ms 21128 KB Output is correct
46 Correct 63 ms 22612 KB Output is correct
47 Correct 105 ms 25672 KB Output is correct
48 Correct 152 ms 30976 KB Output is correct
49 Correct 149 ms 30280 KB Output is correct
50 Correct 120 ms 25696 KB Output is correct
51 Correct 96 ms 25672 KB Output is correct
52 Correct 114 ms 25928 KB Output is correct
53 Correct 147 ms 24548 KB Output is correct
54 Correct 115 ms 25416 KB Output is correct
55 Correct 8 ms 13136 KB Output is correct
56 Correct 11 ms 13304 KB Output is correct
57 Correct 57 ms 20304 KB Output is correct
58 Correct 29 ms 19804 KB Output is correct
59 Correct 70 ms 22376 KB Output is correct
60 Correct 284 ms 32484 KB Output is correct
61 Correct 121 ms 25932 KB Output is correct
62 Correct 133 ms 27976 KB Output is correct
63 Correct 160 ms 27880 KB Output is correct
64 Correct 290 ms 28236 KB Output is correct
65 Correct 127 ms 26756 KB Output is correct
66 Correct 269 ms 31560 KB Output is correct
67 Correct 67 ms 29140 KB Output is correct
68 Correct 155 ms 28744 KB Output is correct
69 Correct 141 ms 28748 KB Output is correct
70 Correct 138 ms 28232 KB Output is correct