# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
720701 |
2023-04-09T03:48:22 Z |
joelgun14 |
Race (IOI11_race) |
C++17 |
|
413 ms |
93016 KB |
#include "race.h"
#include <bits/stdc++.h>
#define ll long long
using namespace std;
int l;
int res = 1e9;
const int lim = 2e5 + 5;
int depth[lim];
bool vis[lim];
vector<pair<int, int>> edges[lim];
struct disjoint_set {
int h[lim], sz[lim], d[lim];
ll shift[lim];
// fi -> distance
// se -> depth
// cari depth terkecil
set<pair<int, int>> a[lim];
disjoint_set() {
memset(h, -1, sizeof(h));
//memset(sz, 0, sizeof(sz));
fill(sz, sz + lim, 1);
memset(shift, 0, sizeof(shift));
memset(d, -1, sizeof(d));
}
int fh(int nd) {
return h[nd] == -1 ? nd : h[nd] = fh(h[nd]);
}
bool merge(int x, int y) {
x = fh(x), y = fh(y);
if(x != y) {
if(sz[x] < sz[y])
swap(x, y);
sz[x] += sz[y];
h[y] = x;
if(a[x].size() < a[y].size()) {
swap(a[x], a[y]);
swap(shift[x], shift[y]);
}
//cout << d[x] << " " << d[y] << endl;
//cout << x << " " << y << endl;
d[x] = min(d[x], d[y]);
for(auto i : a[y]) {
// coba cari di a[x] yg panjangnya pas
int target = l - i.first - shift[x] - shift[y];
// cari target di a[x];
if(a[x].lower_bound(make_pair(target, 0)) != a[x].end() && (*a[x].lower_bound(make_pair(target, 0))).first == target) {
//cout << d[x] << endl;
//cout << i.first + shift[y] << " " << (*a[x].lower_bound(make_pair(target, 0))).first + shift[x] << endl;
//cout << i.second << " " << (*a[x].lower_bound(make_pair(target, 0))).second << endl;
res = min(res, (*a[x].lower_bound(make_pair(target, 0))).second + i.second - 2 * d[x]);
}
}
for(auto i : a[y]) {
auto tmp = i;
tmp.first += shift[y] - shift[x];
//cout << x << " " << shift[x] << " " << tmp.first << " " << tmp.second << endl;
a[x].insert(tmp);
}
//for(auto i : a[x]) {
//cout << "CUR " << x << " " << shift[x] << " " << i.first << " " << i.second << endl;
//}
}
return x != y;
}
};
disjoint_set dsu;
void dfs(int nd = 0) {
//cout << "NODE " << nd << " " << depth[nd] << endl;
vis[nd] = 1;
dsu.a[nd].insert(make_pair(0, depth[nd]));
dsu.d[nd] = depth[nd];
for(auto i : edges[nd]) {
if(!vis[i.first]) {
depth[i.first] = depth[nd] + 1;
dfs(i.first);
dsu.shift[dsu.fh(i.first)] += i.second;
//cout << "MERGE " << nd << endl;
dsu.merge(i.first, nd);
}
}
}
int best_path(int N, int K, int H[][2], int L[])
{
l = K;
for(int i = 0; i < N - 1; ++i) {
edges[H[i][0]].push_back(make_pair(H[i][1], L[i]));
edges[H[i][1]].push_back(make_pair(H[i][0], L[i]));
}
dfs();
if(res == 1e9)
return -1;
else
return res;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
18260 KB |
Output is correct |
2 |
Correct |
8 ms |
18260 KB |
Output is correct |
3 |
Correct |
9 ms |
18280 KB |
Output is correct |
4 |
Correct |
9 ms |
18332 KB |
Output is correct |
5 |
Correct |
9 ms |
18260 KB |
Output is correct |
6 |
Correct |
9 ms |
18248 KB |
Output is correct |
7 |
Correct |
10 ms |
18260 KB |
Output is correct |
8 |
Correct |
10 ms |
18316 KB |
Output is correct |
9 |
Correct |
10 ms |
18252 KB |
Output is correct |
10 |
Correct |
9 ms |
18364 KB |
Output is correct |
11 |
Correct |
10 ms |
18260 KB |
Output is correct |
12 |
Correct |
10 ms |
18248 KB |
Output is correct |
13 |
Correct |
9 ms |
18256 KB |
Output is correct |
14 |
Correct |
10 ms |
18260 KB |
Output is correct |
15 |
Correct |
9 ms |
18260 KB |
Output is correct |
16 |
Correct |
9 ms |
18264 KB |
Output is correct |
17 |
Correct |
10 ms |
18260 KB |
Output is correct |
18 |
Correct |
9 ms |
18260 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
18260 KB |
Output is correct |
2 |
Correct |
8 ms |
18260 KB |
Output is correct |
3 |
Correct |
9 ms |
18280 KB |
Output is correct |
4 |
Correct |
9 ms |
18332 KB |
Output is correct |
5 |
Correct |
9 ms |
18260 KB |
Output is correct |
6 |
Correct |
9 ms |
18248 KB |
Output is correct |
7 |
Correct |
10 ms |
18260 KB |
Output is correct |
8 |
Correct |
10 ms |
18316 KB |
Output is correct |
9 |
Correct |
10 ms |
18252 KB |
Output is correct |
10 |
Correct |
9 ms |
18364 KB |
Output is correct |
11 |
Correct |
10 ms |
18260 KB |
Output is correct |
12 |
Correct |
10 ms |
18248 KB |
Output is correct |
13 |
Correct |
9 ms |
18256 KB |
Output is correct |
14 |
Correct |
10 ms |
18260 KB |
Output is correct |
15 |
Correct |
9 ms |
18260 KB |
Output is correct |
16 |
Correct |
9 ms |
18264 KB |
Output is correct |
17 |
Correct |
10 ms |
18260 KB |
Output is correct |
18 |
Correct |
9 ms |
18260 KB |
Output is correct |
19 |
Correct |
9 ms |
18260 KB |
Output is correct |
20 |
Correct |
9 ms |
18252 KB |
Output is correct |
21 |
Correct |
9 ms |
18516 KB |
Output is correct |
22 |
Correct |
10 ms |
18568 KB |
Output is correct |
23 |
Correct |
10 ms |
18464 KB |
Output is correct |
24 |
Correct |
11 ms |
18468 KB |
Output is correct |
25 |
Correct |
10 ms |
18464 KB |
Output is correct |
26 |
Correct |
11 ms |
18512 KB |
Output is correct |
27 |
Correct |
10 ms |
18468 KB |
Output is correct |
28 |
Correct |
11 ms |
18576 KB |
Output is correct |
29 |
Correct |
10 ms |
18460 KB |
Output is correct |
30 |
Correct |
11 ms |
18516 KB |
Output is correct |
31 |
Correct |
10 ms |
18516 KB |
Output is correct |
32 |
Correct |
10 ms |
18516 KB |
Output is correct |
33 |
Correct |
10 ms |
18516 KB |
Output is correct |
34 |
Correct |
10 ms |
18516 KB |
Output is correct |
35 |
Correct |
10 ms |
18516 KB |
Output is correct |
36 |
Correct |
10 ms |
18460 KB |
Output is correct |
37 |
Correct |
11 ms |
18456 KB |
Output is correct |
38 |
Correct |
12 ms |
18464 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
18260 KB |
Output is correct |
2 |
Correct |
8 ms |
18260 KB |
Output is correct |
3 |
Correct |
9 ms |
18280 KB |
Output is correct |
4 |
Correct |
9 ms |
18332 KB |
Output is correct |
5 |
Correct |
9 ms |
18260 KB |
Output is correct |
6 |
Correct |
9 ms |
18248 KB |
Output is correct |
7 |
Correct |
10 ms |
18260 KB |
Output is correct |
8 |
Correct |
10 ms |
18316 KB |
Output is correct |
9 |
Correct |
10 ms |
18252 KB |
Output is correct |
10 |
Correct |
9 ms |
18364 KB |
Output is correct |
11 |
Correct |
10 ms |
18260 KB |
Output is correct |
12 |
Correct |
10 ms |
18248 KB |
Output is correct |
13 |
Correct |
9 ms |
18256 KB |
Output is correct |
14 |
Correct |
10 ms |
18260 KB |
Output is correct |
15 |
Correct |
9 ms |
18260 KB |
Output is correct |
16 |
Correct |
9 ms |
18264 KB |
Output is correct |
17 |
Correct |
10 ms |
18260 KB |
Output is correct |
18 |
Correct |
9 ms |
18260 KB |
Output is correct |
19 |
Correct |
140 ms |
39020 KB |
Output is correct |
20 |
Correct |
152 ms |
40308 KB |
Output is correct |
21 |
Correct |
156 ms |
39788 KB |
Output is correct |
22 |
Correct |
151 ms |
38732 KB |
Output is correct |
23 |
Correct |
175 ms |
49796 KB |
Output is correct |
24 |
Correct |
152 ms |
39600 KB |
Output is correct |
25 |
Correct |
139 ms |
45836 KB |
Output is correct |
26 |
Correct |
79 ms |
52524 KB |
Output is correct |
27 |
Correct |
223 ms |
48888 KB |
Output is correct |
28 |
Correct |
303 ms |
87128 KB |
Output is correct |
29 |
Correct |
290 ms |
85168 KB |
Output is correct |
30 |
Correct |
210 ms |
48780 KB |
Output is correct |
31 |
Correct |
232 ms |
48744 KB |
Output is correct |
32 |
Correct |
303 ms |
48792 KB |
Output is correct |
33 |
Correct |
248 ms |
49884 KB |
Output is correct |
34 |
Correct |
335 ms |
74904 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
18260 KB |
Output is correct |
2 |
Correct |
8 ms |
18260 KB |
Output is correct |
3 |
Correct |
9 ms |
18280 KB |
Output is correct |
4 |
Correct |
9 ms |
18332 KB |
Output is correct |
5 |
Correct |
9 ms |
18260 KB |
Output is correct |
6 |
Correct |
9 ms |
18248 KB |
Output is correct |
7 |
Correct |
10 ms |
18260 KB |
Output is correct |
8 |
Correct |
10 ms |
18316 KB |
Output is correct |
9 |
Correct |
10 ms |
18252 KB |
Output is correct |
10 |
Correct |
9 ms |
18364 KB |
Output is correct |
11 |
Correct |
10 ms |
18260 KB |
Output is correct |
12 |
Correct |
10 ms |
18248 KB |
Output is correct |
13 |
Correct |
9 ms |
18256 KB |
Output is correct |
14 |
Correct |
10 ms |
18260 KB |
Output is correct |
15 |
Correct |
9 ms |
18260 KB |
Output is correct |
16 |
Correct |
9 ms |
18264 KB |
Output is correct |
17 |
Correct |
10 ms |
18260 KB |
Output is correct |
18 |
Correct |
9 ms |
18260 KB |
Output is correct |
19 |
Correct |
9 ms |
18260 KB |
Output is correct |
20 |
Correct |
9 ms |
18252 KB |
Output is correct |
21 |
Correct |
9 ms |
18516 KB |
Output is correct |
22 |
Correct |
10 ms |
18568 KB |
Output is correct |
23 |
Correct |
10 ms |
18464 KB |
Output is correct |
24 |
Correct |
11 ms |
18468 KB |
Output is correct |
25 |
Correct |
10 ms |
18464 KB |
Output is correct |
26 |
Correct |
11 ms |
18512 KB |
Output is correct |
27 |
Correct |
10 ms |
18468 KB |
Output is correct |
28 |
Correct |
11 ms |
18576 KB |
Output is correct |
29 |
Correct |
10 ms |
18460 KB |
Output is correct |
30 |
Correct |
11 ms |
18516 KB |
Output is correct |
31 |
Correct |
10 ms |
18516 KB |
Output is correct |
32 |
Correct |
10 ms |
18516 KB |
Output is correct |
33 |
Correct |
10 ms |
18516 KB |
Output is correct |
34 |
Correct |
10 ms |
18516 KB |
Output is correct |
35 |
Correct |
10 ms |
18516 KB |
Output is correct |
36 |
Correct |
10 ms |
18460 KB |
Output is correct |
37 |
Correct |
11 ms |
18456 KB |
Output is correct |
38 |
Correct |
12 ms |
18464 KB |
Output is correct |
39 |
Correct |
140 ms |
39020 KB |
Output is correct |
40 |
Correct |
152 ms |
40308 KB |
Output is correct |
41 |
Correct |
156 ms |
39788 KB |
Output is correct |
42 |
Correct |
151 ms |
38732 KB |
Output is correct |
43 |
Correct |
175 ms |
49796 KB |
Output is correct |
44 |
Correct |
152 ms |
39600 KB |
Output is correct |
45 |
Correct |
139 ms |
45836 KB |
Output is correct |
46 |
Correct |
79 ms |
52524 KB |
Output is correct |
47 |
Correct |
223 ms |
48888 KB |
Output is correct |
48 |
Correct |
303 ms |
87128 KB |
Output is correct |
49 |
Correct |
290 ms |
85168 KB |
Output is correct |
50 |
Correct |
210 ms |
48780 KB |
Output is correct |
51 |
Correct |
232 ms |
48744 KB |
Output is correct |
52 |
Correct |
303 ms |
48792 KB |
Output is correct |
53 |
Correct |
248 ms |
49884 KB |
Output is correct |
54 |
Correct |
335 ms |
74904 KB |
Output is correct |
55 |
Correct |
24 ms |
21020 KB |
Output is correct |
56 |
Correct |
16 ms |
20052 KB |
Output is correct |
57 |
Correct |
102 ms |
36276 KB |
Output is correct |
58 |
Correct |
56 ms |
29584 KB |
Output is correct |
59 |
Correct |
76 ms |
52596 KB |
Output is correct |
60 |
Correct |
294 ms |
85660 KB |
Output is correct |
61 |
Correct |
237 ms |
53116 KB |
Output is correct |
62 |
Correct |
189 ms |
48852 KB |
Output is correct |
63 |
Correct |
314 ms |
48912 KB |
Output is correct |
64 |
Correct |
407 ms |
93016 KB |
Output is correct |
65 |
Correct |
413 ms |
86936 KB |
Output is correct |
66 |
Correct |
296 ms |
80580 KB |
Output is correct |
67 |
Correct |
197 ms |
42404 KB |
Output is correct |
68 |
Correct |
353 ms |
60576 KB |
Output is correct |
69 |
Correct |
404 ms |
64976 KB |
Output is correct |
70 |
Correct |
340 ms |
58948 KB |
Output is correct |