# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
819872 |
2023-08-10T14:48:09 Z |
hungby04 |
Race (IOI11_race) |
C++17 |
|
359 ms |
49200 KB |
/// HuDzG
#include <bits/stdc++.h>
#define reset(a) memset(a,0,sizeof(a))
#define ll long long
#define ld long double
#define endl '\n'
#define AutoAC int main()
#define OO 1000000007
#define F first
#define S second
#define pii pair <int, int>
#define pll pair <ll, ll>
#define pb push_back
#define mp make_pair
#define nmax 1000005
#define HUNGIT ""
#define MOD 1000000007
using namespace std;
int n, k;
vector <pii> adj[nmax];
int res = OO;
int cntChild[nmax], Min[nmax];
bool isCentroid[nmax];
int getCntChild(int u, int p)
{
cntChild[u] = 1;
for(pii v : adj[u])
if(v.F != p && !isCentroid[v.F]) cntChild[u] += getCntChild(v.F, u);
return cntChild[u];
}
int findCentroid(int u, int p, int Size)
{
for(pii v : adj[u])
if(v.F != p && !isCentroid[v.F] && cntChild[v.F] > Size) return findCentroid(v.F, u, Size);
return u;
}
void dfs(int u, int p, bool isFill, int length, int depth)
{
if(length > k) return;
if(isFill) Min[length] = min(Min[length], depth);
else res = min(res, depth + Min[k - length]);
for(pii v : adj[u])
{
if(v.F != p && !isCentroid[v.F])
{
dfs(v.F, u, isFill, length + v.S, depth + 1);
}
}
}
void dfsReset(int u, int p, int length)
{
if(length > k) return;
Min[length] = OO;
for(pii v : adj[u])
if(v.F != p && !isCentroid[v.F]) dfsReset(v.F, u, length + v.S);
}
void decompose(int u)
{
int centroid = findCentroid(u, 0, getCntChild(u, 0) >> 1);
isCentroid[centroid] = 1;
Min[0] = 0;
for(pii v : adj[centroid])
if(!isCentroid[v.F])
{
dfs(v.F, centroid, 0, v.S, 1);
dfs(v.F, centroid, 1, v.S, 1);
}
dfsReset(centroid, 0, 0);
for(pii v : adj[centroid])
if(!isCentroid[v.F]) decompose(v.F);
}
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];
u++; v++;
adj[u].pb(mp(v, w));
adj[v].pb(mp(u, w));
}
fill(Min + 1, Min + 1 + k, OO);
decompose(1);
return (res == OO ? -1 : res);
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
23764 KB |
Output is correct |
2 |
Correct |
13 ms |
23760 KB |
Output is correct |
3 |
Correct |
13 ms |
23764 KB |
Output is correct |
4 |
Correct |
12 ms |
23744 KB |
Output is correct |
5 |
Correct |
13 ms |
23728 KB |
Output is correct |
6 |
Correct |
12 ms |
23728 KB |
Output is correct |
7 |
Correct |
12 ms |
23764 KB |
Output is correct |
8 |
Correct |
11 ms |
23812 KB |
Output is correct |
9 |
Correct |
12 ms |
23764 KB |
Output is correct |
10 |
Correct |
12 ms |
23764 KB |
Output is correct |
11 |
Correct |
12 ms |
23792 KB |
Output is correct |
12 |
Correct |
13 ms |
23736 KB |
Output is correct |
13 |
Correct |
11 ms |
23764 KB |
Output is correct |
14 |
Correct |
11 ms |
23764 KB |
Output is correct |
15 |
Correct |
11 ms |
23764 KB |
Output is correct |
16 |
Correct |
12 ms |
23764 KB |
Output is correct |
17 |
Correct |
12 ms |
23804 KB |
Output is correct |
18 |
Correct |
11 ms |
23764 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
23764 KB |
Output is correct |
2 |
Correct |
13 ms |
23760 KB |
Output is correct |
3 |
Correct |
13 ms |
23764 KB |
Output is correct |
4 |
Correct |
12 ms |
23744 KB |
Output is correct |
5 |
Correct |
13 ms |
23728 KB |
Output is correct |
6 |
Correct |
12 ms |
23728 KB |
Output is correct |
7 |
Correct |
12 ms |
23764 KB |
Output is correct |
8 |
Correct |
11 ms |
23812 KB |
Output is correct |
9 |
Correct |
12 ms |
23764 KB |
Output is correct |
10 |
Correct |
12 ms |
23764 KB |
Output is correct |
11 |
Correct |
12 ms |
23792 KB |
Output is correct |
12 |
Correct |
13 ms |
23736 KB |
Output is correct |
13 |
Correct |
11 ms |
23764 KB |
Output is correct |
14 |
Correct |
11 ms |
23764 KB |
Output is correct |
15 |
Correct |
11 ms |
23764 KB |
Output is correct |
16 |
Correct |
12 ms |
23764 KB |
Output is correct |
17 |
Correct |
12 ms |
23804 KB |
Output is correct |
18 |
Correct |
11 ms |
23764 KB |
Output is correct |
19 |
Correct |
11 ms |
23764 KB |
Output is correct |
20 |
Correct |
11 ms |
23720 KB |
Output is correct |
21 |
Correct |
12 ms |
23852 KB |
Output is correct |
22 |
Correct |
13 ms |
27472 KB |
Output is correct |
23 |
Correct |
13 ms |
26708 KB |
Output is correct |
24 |
Correct |
14 ms |
27240 KB |
Output is correct |
25 |
Correct |
17 ms |
27268 KB |
Output is correct |
26 |
Correct |
14 ms |
25172 KB |
Output is correct |
27 |
Correct |
14 ms |
26960 KB |
Output is correct |
28 |
Correct |
13 ms |
24532 KB |
Output is correct |
29 |
Correct |
13 ms |
25044 KB |
Output is correct |
30 |
Correct |
16 ms |
25308 KB |
Output is correct |
31 |
Correct |
14 ms |
26404 KB |
Output is correct |
32 |
Correct |
14 ms |
26544 KB |
Output is correct |
33 |
Correct |
14 ms |
26924 KB |
Output is correct |
34 |
Correct |
13 ms |
26172 KB |
Output is correct |
35 |
Correct |
14 ms |
26968 KB |
Output is correct |
36 |
Correct |
14 ms |
27436 KB |
Output is correct |
37 |
Correct |
14 ms |
26964 KB |
Output is correct |
38 |
Correct |
14 ms |
25856 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
23764 KB |
Output is correct |
2 |
Correct |
13 ms |
23760 KB |
Output is correct |
3 |
Correct |
13 ms |
23764 KB |
Output is correct |
4 |
Correct |
12 ms |
23744 KB |
Output is correct |
5 |
Correct |
13 ms |
23728 KB |
Output is correct |
6 |
Correct |
12 ms |
23728 KB |
Output is correct |
7 |
Correct |
12 ms |
23764 KB |
Output is correct |
8 |
Correct |
11 ms |
23812 KB |
Output is correct |
9 |
Correct |
12 ms |
23764 KB |
Output is correct |
10 |
Correct |
12 ms |
23764 KB |
Output is correct |
11 |
Correct |
12 ms |
23792 KB |
Output is correct |
12 |
Correct |
13 ms |
23736 KB |
Output is correct |
13 |
Correct |
11 ms |
23764 KB |
Output is correct |
14 |
Correct |
11 ms |
23764 KB |
Output is correct |
15 |
Correct |
11 ms |
23764 KB |
Output is correct |
16 |
Correct |
12 ms |
23764 KB |
Output is correct |
17 |
Correct |
12 ms |
23804 KB |
Output is correct |
18 |
Correct |
11 ms |
23764 KB |
Output is correct |
19 |
Correct |
123 ms |
29012 KB |
Output is correct |
20 |
Correct |
104 ms |
29124 KB |
Output is correct |
21 |
Correct |
109 ms |
29144 KB |
Output is correct |
22 |
Correct |
113 ms |
29104 KB |
Output is correct |
23 |
Correct |
64 ms |
29352 KB |
Output is correct |
24 |
Correct |
52 ms |
29256 KB |
Output is correct |
25 |
Correct |
104 ms |
31892 KB |
Output is correct |
26 |
Correct |
89 ms |
34800 KB |
Output is correct |
27 |
Correct |
134 ms |
34624 KB |
Output is correct |
28 |
Correct |
192 ms |
45812 KB |
Output is correct |
29 |
Correct |
211 ms |
44928 KB |
Output is correct |
30 |
Correct |
127 ms |
34640 KB |
Output is correct |
31 |
Correct |
126 ms |
34596 KB |
Output is correct |
32 |
Correct |
140 ms |
34608 KB |
Output is correct |
33 |
Correct |
211 ms |
33700 KB |
Output is correct |
34 |
Correct |
133 ms |
33484 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
23764 KB |
Output is correct |
2 |
Correct |
13 ms |
23760 KB |
Output is correct |
3 |
Correct |
13 ms |
23764 KB |
Output is correct |
4 |
Correct |
12 ms |
23744 KB |
Output is correct |
5 |
Correct |
13 ms |
23728 KB |
Output is correct |
6 |
Correct |
12 ms |
23728 KB |
Output is correct |
7 |
Correct |
12 ms |
23764 KB |
Output is correct |
8 |
Correct |
11 ms |
23812 KB |
Output is correct |
9 |
Correct |
12 ms |
23764 KB |
Output is correct |
10 |
Correct |
12 ms |
23764 KB |
Output is correct |
11 |
Correct |
12 ms |
23792 KB |
Output is correct |
12 |
Correct |
13 ms |
23736 KB |
Output is correct |
13 |
Correct |
11 ms |
23764 KB |
Output is correct |
14 |
Correct |
11 ms |
23764 KB |
Output is correct |
15 |
Correct |
11 ms |
23764 KB |
Output is correct |
16 |
Correct |
12 ms |
23764 KB |
Output is correct |
17 |
Correct |
12 ms |
23804 KB |
Output is correct |
18 |
Correct |
11 ms |
23764 KB |
Output is correct |
19 |
Correct |
11 ms |
23764 KB |
Output is correct |
20 |
Correct |
11 ms |
23720 KB |
Output is correct |
21 |
Correct |
12 ms |
23852 KB |
Output is correct |
22 |
Correct |
13 ms |
27472 KB |
Output is correct |
23 |
Correct |
13 ms |
26708 KB |
Output is correct |
24 |
Correct |
14 ms |
27240 KB |
Output is correct |
25 |
Correct |
17 ms |
27268 KB |
Output is correct |
26 |
Correct |
14 ms |
25172 KB |
Output is correct |
27 |
Correct |
14 ms |
26960 KB |
Output is correct |
28 |
Correct |
13 ms |
24532 KB |
Output is correct |
29 |
Correct |
13 ms |
25044 KB |
Output is correct |
30 |
Correct |
16 ms |
25308 KB |
Output is correct |
31 |
Correct |
14 ms |
26404 KB |
Output is correct |
32 |
Correct |
14 ms |
26544 KB |
Output is correct |
33 |
Correct |
14 ms |
26924 KB |
Output is correct |
34 |
Correct |
13 ms |
26172 KB |
Output is correct |
35 |
Correct |
14 ms |
26968 KB |
Output is correct |
36 |
Correct |
14 ms |
27436 KB |
Output is correct |
37 |
Correct |
14 ms |
26964 KB |
Output is correct |
38 |
Correct |
14 ms |
25856 KB |
Output is correct |
39 |
Correct |
123 ms |
29012 KB |
Output is correct |
40 |
Correct |
104 ms |
29124 KB |
Output is correct |
41 |
Correct |
109 ms |
29144 KB |
Output is correct |
42 |
Correct |
113 ms |
29104 KB |
Output is correct |
43 |
Correct |
64 ms |
29352 KB |
Output is correct |
44 |
Correct |
52 ms |
29256 KB |
Output is correct |
45 |
Correct |
104 ms |
31892 KB |
Output is correct |
46 |
Correct |
89 ms |
34800 KB |
Output is correct |
47 |
Correct |
134 ms |
34624 KB |
Output is correct |
48 |
Correct |
192 ms |
45812 KB |
Output is correct |
49 |
Correct |
211 ms |
44928 KB |
Output is correct |
50 |
Correct |
127 ms |
34640 KB |
Output is correct |
51 |
Correct |
126 ms |
34596 KB |
Output is correct |
52 |
Correct |
140 ms |
34608 KB |
Output is correct |
53 |
Correct |
211 ms |
33700 KB |
Output is correct |
54 |
Correct |
133 ms |
33484 KB |
Output is correct |
55 |
Correct |
22 ms |
24380 KB |
Output is correct |
56 |
Correct |
19 ms |
24276 KB |
Output is correct |
57 |
Correct |
69 ms |
29388 KB |
Output is correct |
58 |
Correct |
38 ms |
29356 KB |
Output is correct |
59 |
Correct |
97 ms |
35640 KB |
Output is correct |
60 |
Correct |
359 ms |
49200 KB |
Output is correct |
61 |
Correct |
137 ms |
34600 KB |
Output is correct |
62 |
Correct |
170 ms |
38552 KB |
Output is correct |
63 |
Correct |
274 ms |
38584 KB |
Output is correct |
64 |
Correct |
353 ms |
36428 KB |
Output is correct |
65 |
Correct |
142 ms |
34612 KB |
Output is correct |
66 |
Correct |
323 ms |
46752 KB |
Output is correct |
67 |
Correct |
87 ms |
38780 KB |
Output is correct |
68 |
Correct |
197 ms |
38812 KB |
Output is correct |
69 |
Correct |
192 ms |
38728 KB |
Output is correct |
70 |
Correct |
207 ms |
38240 KB |
Output is correct |