# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
104398 |
2019-04-06T16:12:53 Z |
bagd |
Race (IOI11_race) |
C++14 |
|
889 ms |
30328 KB |
#include <bits/stdc++.h>
#include "race.h"
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define ll long long
using namespace std;
const int MAXN = 200100;
vector <pair <int, int> > ve[MAXN];
int sub[MAXN];
int bio[MAXN], cnt;
int n, k;
int out_len = MAXN;
int len[5 * MAXN];
int date[5 * MAXN];
int num;
int tmp;
void rek1(int x, int l, int di) {
if (l > k) return;
if (k >= l && date[k - l] == num) {
out_len = min(out_len, di + len[k - l]);
}
bio[x] = cnt;
for (auto tr : ve[x]) {
int y = tr.first, d = tr.second;
if (bio[y] >= cnt) continue;
rek1(y, l + d, di + 1);
}
return;
}
void rek2(int x, int l, int di) {
if (l > k) return;
if (date[l] < num) {
date[l] = num;
len[l] = 1e9;
}
len[l] = min(len[l], di);
bio[x] = cnt;
for (auto tr : ve[x]) {
int y = tr.first, d = tr.second;
if (bio[y] >= cnt) continue;
rek2(y, l + d, di + 1);
}
return;
}
void solve(int x) {
bio[x] = 1e9;
num++;
cnt++;
date[0] = num, len[0] = 0;
for (auto tr : ve[x]) {
int y = tr.first, d = tr.second;
if (bio[y] >= cnt) continue;
rek1(y, d, 1);
cnt++;
rek2(y, d, 1);
cnt++;
}
return;
}
int si;
void dfs(int x) {
si++;
bio[x] = cnt;
sub[x] = 1;
for (auto tr : ve[x]) {
int y = tr.first;
if (bio[y] >= cnt) continue;
dfs(y);
sub[x] += sub[y];
}
return;
}
int find_centroid(int x) {
bio[x] = cnt;
for (auto tr : ve[x]) {
int y = tr.first;
if (bio[y] >= cnt) continue;
if (sub[y] > si / 2) return find_centroid(y);
}
return x;
}
void decompose(int x) {
cnt++, si = 0;
dfs(x);
cnt++;
int c = find_centroid(x);
solve(c);
for (auto tr : ve[c]) {
int y = tr.first;
if (bio[y] != 1e9) decompose(y);
}
return;
}
int best_path(int N, int K, int H[][2], int L[]) {
n = N, k = K;
REP(i, n) {
int a = H[i][0], b = H[i][1], c = L[i];
ve[a].push_back({b, c});
ve[b].push_back({a, c});
}
decompose(0);
if (out_len == MAXN) return -1;
return out_len;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
4992 KB |
Output is correct |
2 |
Correct |
6 ms |
5120 KB |
Output is correct |
3 |
Correct |
7 ms |
5120 KB |
Output is correct |
4 |
Correct |
7 ms |
4992 KB |
Output is correct |
5 |
Correct |
7 ms |
4992 KB |
Output is correct |
6 |
Correct |
8 ms |
5120 KB |
Output is correct |
7 |
Correct |
8 ms |
5120 KB |
Output is correct |
8 |
Correct |
7 ms |
5120 KB |
Output is correct |
9 |
Correct |
7 ms |
5120 KB |
Output is correct |
10 |
Correct |
7 ms |
5120 KB |
Output is correct |
11 |
Correct |
7 ms |
4992 KB |
Output is correct |
12 |
Correct |
7 ms |
5084 KB |
Output is correct |
13 |
Correct |
8 ms |
4992 KB |
Output is correct |
14 |
Correct |
7 ms |
4992 KB |
Output is correct |
15 |
Correct |
7 ms |
4992 KB |
Output is correct |
16 |
Correct |
8 ms |
5120 KB |
Output is correct |
17 |
Correct |
6 ms |
4992 KB |
Output is correct |
18 |
Correct |
6 ms |
5120 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
4992 KB |
Output is correct |
2 |
Correct |
6 ms |
5120 KB |
Output is correct |
3 |
Correct |
7 ms |
5120 KB |
Output is correct |
4 |
Correct |
7 ms |
4992 KB |
Output is correct |
5 |
Correct |
7 ms |
4992 KB |
Output is correct |
6 |
Correct |
8 ms |
5120 KB |
Output is correct |
7 |
Correct |
8 ms |
5120 KB |
Output is correct |
8 |
Correct |
7 ms |
5120 KB |
Output is correct |
9 |
Correct |
7 ms |
5120 KB |
Output is correct |
10 |
Correct |
7 ms |
5120 KB |
Output is correct |
11 |
Correct |
7 ms |
4992 KB |
Output is correct |
12 |
Correct |
7 ms |
5084 KB |
Output is correct |
13 |
Correct |
8 ms |
4992 KB |
Output is correct |
14 |
Correct |
7 ms |
4992 KB |
Output is correct |
15 |
Correct |
7 ms |
4992 KB |
Output is correct |
16 |
Correct |
8 ms |
5120 KB |
Output is correct |
17 |
Correct |
6 ms |
4992 KB |
Output is correct |
18 |
Correct |
6 ms |
5120 KB |
Output is correct |
19 |
Correct |
6 ms |
4992 KB |
Output is correct |
20 |
Correct |
6 ms |
5120 KB |
Output is correct |
21 |
Correct |
8 ms |
5092 KB |
Output is correct |
22 |
Correct |
15 ms |
10112 KB |
Output is correct |
23 |
Correct |
13 ms |
9344 KB |
Output is correct |
24 |
Correct |
14 ms |
10880 KB |
Output is correct |
25 |
Correct |
13 ms |
8576 KB |
Output is correct |
26 |
Correct |
10 ms |
7808 KB |
Output is correct |
27 |
Correct |
7 ms |
5120 KB |
Output is correct |
28 |
Correct |
10 ms |
6656 KB |
Output is correct |
29 |
Correct |
10 ms |
7680 KB |
Output is correct |
30 |
Correct |
10 ms |
7936 KB |
Output is correct |
31 |
Correct |
10 ms |
8704 KB |
Output is correct |
32 |
Correct |
11 ms |
8832 KB |
Output is correct |
33 |
Correct |
13 ms |
10496 KB |
Output is correct |
34 |
Correct |
14 ms |
9600 KB |
Output is correct |
35 |
Correct |
15 ms |
11008 KB |
Output is correct |
36 |
Correct |
14 ms |
11520 KB |
Output is correct |
37 |
Correct |
11 ms |
8960 KB |
Output is correct |
38 |
Correct |
10 ms |
7424 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
4992 KB |
Output is correct |
2 |
Correct |
6 ms |
5120 KB |
Output is correct |
3 |
Correct |
7 ms |
5120 KB |
Output is correct |
4 |
Correct |
7 ms |
4992 KB |
Output is correct |
5 |
Correct |
7 ms |
4992 KB |
Output is correct |
6 |
Correct |
8 ms |
5120 KB |
Output is correct |
7 |
Correct |
8 ms |
5120 KB |
Output is correct |
8 |
Correct |
7 ms |
5120 KB |
Output is correct |
9 |
Correct |
7 ms |
5120 KB |
Output is correct |
10 |
Correct |
7 ms |
5120 KB |
Output is correct |
11 |
Correct |
7 ms |
4992 KB |
Output is correct |
12 |
Correct |
7 ms |
5084 KB |
Output is correct |
13 |
Correct |
8 ms |
4992 KB |
Output is correct |
14 |
Correct |
7 ms |
4992 KB |
Output is correct |
15 |
Correct |
7 ms |
4992 KB |
Output is correct |
16 |
Correct |
8 ms |
5120 KB |
Output is correct |
17 |
Correct |
6 ms |
4992 KB |
Output is correct |
18 |
Correct |
6 ms |
5120 KB |
Output is correct |
19 |
Correct |
172 ms |
10748 KB |
Output is correct |
20 |
Correct |
262 ms |
10616 KB |
Output is correct |
21 |
Correct |
226 ms |
10868 KB |
Output is correct |
22 |
Correct |
268 ms |
10860 KB |
Output is correct |
23 |
Correct |
133 ms |
10872 KB |
Output is correct |
24 |
Correct |
88 ms |
10768 KB |
Output is correct |
25 |
Correct |
243 ms |
12664 KB |
Output is correct |
26 |
Correct |
118 ms |
14912 KB |
Output is correct |
27 |
Correct |
266 ms |
16512 KB |
Output is correct |
28 |
Correct |
614 ms |
24824 KB |
Output is correct |
29 |
Correct |
577 ms |
24056 KB |
Output is correct |
30 |
Correct |
253 ms |
16588 KB |
Output is correct |
31 |
Correct |
240 ms |
16696 KB |
Output is correct |
32 |
Correct |
344 ms |
16452 KB |
Output is correct |
33 |
Correct |
353 ms |
15352 KB |
Output is correct |
34 |
Correct |
335 ms |
15480 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
4992 KB |
Output is correct |
2 |
Correct |
6 ms |
5120 KB |
Output is correct |
3 |
Correct |
7 ms |
5120 KB |
Output is correct |
4 |
Correct |
7 ms |
4992 KB |
Output is correct |
5 |
Correct |
7 ms |
4992 KB |
Output is correct |
6 |
Correct |
8 ms |
5120 KB |
Output is correct |
7 |
Correct |
8 ms |
5120 KB |
Output is correct |
8 |
Correct |
7 ms |
5120 KB |
Output is correct |
9 |
Correct |
7 ms |
5120 KB |
Output is correct |
10 |
Correct |
7 ms |
5120 KB |
Output is correct |
11 |
Correct |
7 ms |
4992 KB |
Output is correct |
12 |
Correct |
7 ms |
5084 KB |
Output is correct |
13 |
Correct |
8 ms |
4992 KB |
Output is correct |
14 |
Correct |
7 ms |
4992 KB |
Output is correct |
15 |
Correct |
7 ms |
4992 KB |
Output is correct |
16 |
Correct |
8 ms |
5120 KB |
Output is correct |
17 |
Correct |
6 ms |
4992 KB |
Output is correct |
18 |
Correct |
6 ms |
5120 KB |
Output is correct |
19 |
Correct |
6 ms |
4992 KB |
Output is correct |
20 |
Correct |
6 ms |
5120 KB |
Output is correct |
21 |
Correct |
8 ms |
5092 KB |
Output is correct |
22 |
Correct |
15 ms |
10112 KB |
Output is correct |
23 |
Correct |
13 ms |
9344 KB |
Output is correct |
24 |
Correct |
14 ms |
10880 KB |
Output is correct |
25 |
Correct |
13 ms |
8576 KB |
Output is correct |
26 |
Correct |
10 ms |
7808 KB |
Output is correct |
27 |
Correct |
7 ms |
5120 KB |
Output is correct |
28 |
Correct |
10 ms |
6656 KB |
Output is correct |
29 |
Correct |
10 ms |
7680 KB |
Output is correct |
30 |
Correct |
10 ms |
7936 KB |
Output is correct |
31 |
Correct |
10 ms |
8704 KB |
Output is correct |
32 |
Correct |
11 ms |
8832 KB |
Output is correct |
33 |
Correct |
13 ms |
10496 KB |
Output is correct |
34 |
Correct |
14 ms |
9600 KB |
Output is correct |
35 |
Correct |
15 ms |
11008 KB |
Output is correct |
36 |
Correct |
14 ms |
11520 KB |
Output is correct |
37 |
Correct |
11 ms |
8960 KB |
Output is correct |
38 |
Correct |
10 ms |
7424 KB |
Output is correct |
39 |
Correct |
172 ms |
10748 KB |
Output is correct |
40 |
Correct |
262 ms |
10616 KB |
Output is correct |
41 |
Correct |
226 ms |
10868 KB |
Output is correct |
42 |
Correct |
268 ms |
10860 KB |
Output is correct |
43 |
Correct |
133 ms |
10872 KB |
Output is correct |
44 |
Correct |
88 ms |
10768 KB |
Output is correct |
45 |
Correct |
243 ms |
12664 KB |
Output is correct |
46 |
Correct |
118 ms |
14912 KB |
Output is correct |
47 |
Correct |
266 ms |
16512 KB |
Output is correct |
48 |
Correct |
614 ms |
24824 KB |
Output is correct |
49 |
Correct |
577 ms |
24056 KB |
Output is correct |
50 |
Correct |
253 ms |
16588 KB |
Output is correct |
51 |
Correct |
240 ms |
16696 KB |
Output is correct |
52 |
Correct |
344 ms |
16452 KB |
Output is correct |
53 |
Correct |
353 ms |
15352 KB |
Output is correct |
54 |
Correct |
335 ms |
15480 KB |
Output is correct |
55 |
Correct |
17 ms |
5712 KB |
Output is correct |
56 |
Correct |
15 ms |
5552 KB |
Output is correct |
57 |
Correct |
112 ms |
10900 KB |
Output is correct |
58 |
Correct |
51 ms |
10860 KB |
Output is correct |
59 |
Correct |
100 ms |
15608 KB |
Output is correct |
60 |
Correct |
742 ms |
28920 KB |
Output is correct |
61 |
Correct |
268 ms |
16504 KB |
Output is correct |
62 |
Correct |
336 ms |
16500 KB |
Output is correct |
63 |
Correct |
423 ms |
16632 KB |
Output is correct |
64 |
Correct |
889 ms |
18552 KB |
Output is correct |
65 |
Correct |
341 ms |
16516 KB |
Output is correct |
66 |
Correct |
726 ms |
30328 KB |
Output is correct |
67 |
Correct |
216 ms |
16744 KB |
Output is correct |
68 |
Correct |
488 ms |
21976 KB |
Output is correct |
69 |
Correct |
475 ms |
22264 KB |
Output is correct |
70 |
Correct |
428 ms |
21424 KB |
Output is correct |