# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
720145 |
2023-04-07T13:49:41 Z |
ooo |
Race (IOI11_race) |
C++14 |
|
559 ms |
50092 KB |
#include <bits/stdc++.h>
#include "race.h"
using namespace std;
#define ll long long
const int nu = 3e5+5;
const int nuu = 1e6+6;
typedef pair<ll, ll> cap;
ll n, k, s[nu], f[nu], ans = 1e9, hh[nu], ms[nuu], pre[nuu];
bool r[nu];
vector< vector<cap> > g;
int dfs(int u, int t)
{
s[u] = 1;
for(cap x : g[u])
{
int v = x.first;
if(r[v] || v == t) continue;
s[u] += dfs(v, u);
}
return s[u];
}
int get_centroid(int u, int t, int sum)
{
for(cap x : g[u])
{
int v = x.first;
if(r[v] || v == t) continue;
if(s[v]*2 > sum) return get_centroid(v, u, sum);
}
return u;
}
void dfs2(int u, int t, int w, int ok, int c)
{
f[u] = f[t]+w; hh[u] = hh[t]+1;
if(f[u] > k) return ;
if(ok == 1)
{
if(pre[f[u]] != c) pre[f[u]] = c, ms[f[u]] = hh[u];
else ms[f[u]] = min(ms[f[u]], hh[u]);
}
else
{
if(pre[k-f[u]] == c) ans = min(ans, hh[u]+ms[k-f[u]]);
}
for(cap x : g[u])
{
int v = x.first;
ll l = x.second;
if(v == t || r[v]) continue;
dfs2(v, u, l, ok, c);
}
}
void centroid(int u)
{
int cnt = dfs(u, 0);
int c = get_centroid(u, 0, cnt);
r[c] = true;
pre[0] = c; ms[0] = 0;
for(cap x : g[c])
{
int v = x.first;
ll l = x.second;
if(r[v]) continue;
dfs2(v, 0, l, 0, c); dfs2(v, 0, l, 1, c);
}
for(cap x : g[c])
{
int v = x.first;
if(!r[v]) centroid(v);
}
}
int best_path(int x, int y, int H[][2], int L[])
{
n = x; k = y;
g.resize(n+1);
for(int i = 0; i < n-1; ++i)
{
ll u = H[i][0]; ll v = H[i][1]; ll c = L[i];
u++; v++;
g[u].push_back({v, c});
g[v].push_back({u, c});
}
centroid(1);
if(ans == 1e9) ans = -1;
return ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
0 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
0 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
0 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
1 ms |
468 KB |
Output is correct |
22 |
Correct |
4 ms |
7124 KB |
Output is correct |
23 |
Correct |
5 ms |
6100 KB |
Output is correct |
24 |
Correct |
7 ms |
8596 KB |
Output is correct |
25 |
Correct |
5 ms |
6740 KB |
Output is correct |
26 |
Correct |
4 ms |
5076 KB |
Output is correct |
27 |
Correct |
1 ms |
468 KB |
Output is correct |
28 |
Correct |
3 ms |
3540 KB |
Output is correct |
29 |
Correct |
3 ms |
5332 KB |
Output is correct |
30 |
Correct |
4 ms |
5844 KB |
Output is correct |
31 |
Correct |
4 ms |
6996 KB |
Output is correct |
32 |
Correct |
7 ms |
6996 KB |
Output is correct |
33 |
Correct |
6 ms |
9940 KB |
Output is correct |
34 |
Correct |
6 ms |
8404 KB |
Output is correct |
35 |
Correct |
7 ms |
10324 KB |
Output is correct |
36 |
Correct |
10 ms |
11140 KB |
Output is correct |
37 |
Correct |
6 ms |
6868 KB |
Output is correct |
38 |
Correct |
4 ms |
4692 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
0 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
137 ms |
11420 KB |
Output is correct |
20 |
Correct |
141 ms |
12768 KB |
Output is correct |
21 |
Correct |
136 ms |
12688 KB |
Output is correct |
22 |
Correct |
176 ms |
12748 KB |
Output is correct |
23 |
Correct |
75 ms |
13176 KB |
Output is correct |
24 |
Correct |
59 ms |
12444 KB |
Output is correct |
25 |
Correct |
129 ms |
15656 KB |
Output is correct |
26 |
Correct |
110 ms |
18492 KB |
Output is correct |
27 |
Correct |
202 ms |
25840 KB |
Output is correct |
28 |
Correct |
265 ms |
37228 KB |
Output is correct |
29 |
Correct |
313 ms |
36416 KB |
Output is correct |
30 |
Correct |
157 ms |
25840 KB |
Output is correct |
31 |
Correct |
169 ms |
25756 KB |
Output is correct |
32 |
Correct |
211 ms |
25860 KB |
Output is correct |
33 |
Correct |
215 ms |
24596 KB |
Output is correct |
34 |
Correct |
256 ms |
25468 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
0 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
0 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
1 ms |
468 KB |
Output is correct |
22 |
Correct |
4 ms |
7124 KB |
Output is correct |
23 |
Correct |
5 ms |
6100 KB |
Output is correct |
24 |
Correct |
7 ms |
8596 KB |
Output is correct |
25 |
Correct |
5 ms |
6740 KB |
Output is correct |
26 |
Correct |
4 ms |
5076 KB |
Output is correct |
27 |
Correct |
1 ms |
468 KB |
Output is correct |
28 |
Correct |
3 ms |
3540 KB |
Output is correct |
29 |
Correct |
3 ms |
5332 KB |
Output is correct |
30 |
Correct |
4 ms |
5844 KB |
Output is correct |
31 |
Correct |
4 ms |
6996 KB |
Output is correct |
32 |
Correct |
7 ms |
6996 KB |
Output is correct |
33 |
Correct |
6 ms |
9940 KB |
Output is correct |
34 |
Correct |
6 ms |
8404 KB |
Output is correct |
35 |
Correct |
7 ms |
10324 KB |
Output is correct |
36 |
Correct |
10 ms |
11140 KB |
Output is correct |
37 |
Correct |
6 ms |
6868 KB |
Output is correct |
38 |
Correct |
4 ms |
4692 KB |
Output is correct |
39 |
Correct |
137 ms |
11420 KB |
Output is correct |
40 |
Correct |
141 ms |
12768 KB |
Output is correct |
41 |
Correct |
136 ms |
12688 KB |
Output is correct |
42 |
Correct |
176 ms |
12748 KB |
Output is correct |
43 |
Correct |
75 ms |
13176 KB |
Output is correct |
44 |
Correct |
59 ms |
12444 KB |
Output is correct |
45 |
Correct |
129 ms |
15656 KB |
Output is correct |
46 |
Correct |
110 ms |
18492 KB |
Output is correct |
47 |
Correct |
202 ms |
25840 KB |
Output is correct |
48 |
Correct |
265 ms |
37228 KB |
Output is correct |
49 |
Correct |
313 ms |
36416 KB |
Output is correct |
50 |
Correct |
157 ms |
25840 KB |
Output is correct |
51 |
Correct |
169 ms |
25756 KB |
Output is correct |
52 |
Correct |
211 ms |
25860 KB |
Output is correct |
53 |
Correct |
215 ms |
24596 KB |
Output is correct |
54 |
Correct |
256 ms |
25468 KB |
Output is correct |
55 |
Correct |
9 ms |
1608 KB |
Output is correct |
56 |
Correct |
10 ms |
1492 KB |
Output is correct |
57 |
Correct |
77 ms |
13096 KB |
Output is correct |
58 |
Correct |
36 ms |
12092 KB |
Output is correct |
59 |
Correct |
106 ms |
20176 KB |
Output is correct |
60 |
Correct |
531 ms |
45892 KB |
Output is correct |
61 |
Correct |
196 ms |
26000 KB |
Output is correct |
62 |
Correct |
242 ms |
25940 KB |
Output is correct |
63 |
Correct |
256 ms |
25948 KB |
Output is correct |
64 |
Correct |
559 ms |
30248 KB |
Output is correct |
65 |
Correct |
255 ms |
26532 KB |
Output is correct |
66 |
Correct |
447 ms |
50092 KB |
Output is correct |
67 |
Correct |
116 ms |
25108 KB |
Output is correct |
68 |
Correct |
255 ms |
36368 KB |
Output is correct |
69 |
Correct |
240 ms |
36556 KB |
Output is correct |
70 |
Correct |
225 ms |
35004 KB |
Output is correct |