# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
987707 |
2024-05-23T11:42:23 Z |
Tsagana |
Race (IOI11_race) |
C++14 |
|
434 ms |
90076 KB |
#include "race.h"
#include<bits/stdc++.h>
#define all(x) x.begin(), x.end()
#define pq priority_queue
#define lb lower_bound
#define ub upper_bound
#define pb push_back
#define eb emplace_back
#define F first
#define S second
using namespace std;
int d, dsu[200001], cc[200001], lz[200001][2], z, inf=2e9;
bitset<200001> vtd;
vector <pair<int, int>> adj[200001];
multiset<pair<int, int>> ms[200001];
int fd(int x) {
if (dsu[x] == x) return x;
return dsu[x] = fd(dsu[x]);
}
void jo(int x,int y) {
int k, w; x = fd(x); y = fd(y);
if (cc[x] < cc[y]) swap(x, y);
for (auto it: ms[y]) {
k = it.F + lz[y][1];
w = it.S + lz[y][0];
auto it2 = ms[x].lb({d - k - lz[x][1], -inf});
if (it2 != ms[x].end() && it2->F + lz[x][1] == d - k)
z = min(z, w + it2->S + lz[x][0]);
}
for (auto it: ms[y]) {
k = it.F + lz[y][1];
w = it.S + lz[y][0];
ms[x].insert({k - lz[x][1], w - lz[x][0]});
}
dsu[y] = x; cc[x] += cc[y];
}
void dfs(int x) {
vtd[x] = cc[x] = 1; dsu[x] = x;
ms[x].insert({0, 0});
for (auto i: adj[x]) {
int l = i.F, w = i.S;
if (!vtd[l]) {
dfs(l);
lz[fd(l)][0]++;
lz[fd(l)][1] += w;
jo(x,l);
}
}
}
int best_path(int n,int od,int ed[][2],int wg[]) {
int k, l;
d = od;
for (int i = 0; i < n-1; i++) {
k = ed[i][0];
l = ed[i][1];
adj[k].pb({l, wg[i]});
adj[l].pb({k, wg[i]});
}
z = inf;
dfs(0);
if (z == inf) z = -1;
return z;
}
Compilation message
race.cpp: In function 'void dfs(int)':
race.cpp:46:18: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
46 | vtd[x] = cc[x] = 1; dsu[x] = x;
| ~~~~~~^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
14424 KB |
Output is correct |
2 |
Correct |
7 ms |
14428 KB |
Output is correct |
3 |
Correct |
7 ms |
14428 KB |
Output is correct |
4 |
Correct |
9 ms |
14428 KB |
Output is correct |
5 |
Correct |
9 ms |
14424 KB |
Output is correct |
6 |
Correct |
8 ms |
14428 KB |
Output is correct |
7 |
Correct |
7 ms |
14424 KB |
Output is correct |
8 |
Correct |
11 ms |
14428 KB |
Output is correct |
9 |
Correct |
10 ms |
14428 KB |
Output is correct |
10 |
Correct |
9 ms |
14428 KB |
Output is correct |
11 |
Correct |
7 ms |
14428 KB |
Output is correct |
12 |
Correct |
9 ms |
14428 KB |
Output is correct |
13 |
Correct |
8 ms |
14428 KB |
Output is correct |
14 |
Correct |
7 ms |
14484 KB |
Output is correct |
15 |
Correct |
8 ms |
14428 KB |
Output is correct |
16 |
Correct |
8 ms |
14428 KB |
Output is correct |
17 |
Correct |
8 ms |
14428 KB |
Output is correct |
18 |
Correct |
8 ms |
14428 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
14424 KB |
Output is correct |
2 |
Correct |
7 ms |
14428 KB |
Output is correct |
3 |
Correct |
7 ms |
14428 KB |
Output is correct |
4 |
Correct |
9 ms |
14428 KB |
Output is correct |
5 |
Correct |
9 ms |
14424 KB |
Output is correct |
6 |
Correct |
8 ms |
14428 KB |
Output is correct |
7 |
Correct |
7 ms |
14424 KB |
Output is correct |
8 |
Correct |
11 ms |
14428 KB |
Output is correct |
9 |
Correct |
10 ms |
14428 KB |
Output is correct |
10 |
Correct |
9 ms |
14428 KB |
Output is correct |
11 |
Correct |
7 ms |
14428 KB |
Output is correct |
12 |
Correct |
9 ms |
14428 KB |
Output is correct |
13 |
Correct |
8 ms |
14428 KB |
Output is correct |
14 |
Correct |
7 ms |
14484 KB |
Output is correct |
15 |
Correct |
8 ms |
14428 KB |
Output is correct |
16 |
Correct |
8 ms |
14428 KB |
Output is correct |
17 |
Correct |
8 ms |
14428 KB |
Output is correct |
18 |
Correct |
8 ms |
14428 KB |
Output is correct |
19 |
Correct |
7 ms |
14424 KB |
Output is correct |
20 |
Correct |
8 ms |
14428 KB |
Output is correct |
21 |
Correct |
9 ms |
14684 KB |
Output is correct |
22 |
Correct |
9 ms |
14824 KB |
Output is correct |
23 |
Correct |
9 ms |
14680 KB |
Output is correct |
24 |
Correct |
9 ms |
14696 KB |
Output is correct |
25 |
Correct |
8 ms |
14684 KB |
Output is correct |
26 |
Correct |
9 ms |
14680 KB |
Output is correct |
27 |
Correct |
11 ms |
14684 KB |
Output is correct |
28 |
Correct |
11 ms |
14684 KB |
Output is correct |
29 |
Correct |
8 ms |
14884 KB |
Output is correct |
30 |
Correct |
9 ms |
14684 KB |
Output is correct |
31 |
Correct |
8 ms |
14684 KB |
Output is correct |
32 |
Correct |
13 ms |
14684 KB |
Output is correct |
33 |
Correct |
10 ms |
14684 KB |
Output is correct |
34 |
Correct |
9 ms |
14684 KB |
Output is correct |
35 |
Correct |
11 ms |
14684 KB |
Output is correct |
36 |
Correct |
9 ms |
14684 KB |
Output is correct |
37 |
Correct |
9 ms |
14680 KB |
Output is correct |
38 |
Correct |
9 ms |
14684 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
14424 KB |
Output is correct |
2 |
Correct |
7 ms |
14428 KB |
Output is correct |
3 |
Correct |
7 ms |
14428 KB |
Output is correct |
4 |
Correct |
9 ms |
14428 KB |
Output is correct |
5 |
Correct |
9 ms |
14424 KB |
Output is correct |
6 |
Correct |
8 ms |
14428 KB |
Output is correct |
7 |
Correct |
7 ms |
14424 KB |
Output is correct |
8 |
Correct |
11 ms |
14428 KB |
Output is correct |
9 |
Correct |
10 ms |
14428 KB |
Output is correct |
10 |
Correct |
9 ms |
14428 KB |
Output is correct |
11 |
Correct |
7 ms |
14428 KB |
Output is correct |
12 |
Correct |
9 ms |
14428 KB |
Output is correct |
13 |
Correct |
8 ms |
14428 KB |
Output is correct |
14 |
Correct |
7 ms |
14484 KB |
Output is correct |
15 |
Correct |
8 ms |
14428 KB |
Output is correct |
16 |
Correct |
8 ms |
14428 KB |
Output is correct |
17 |
Correct |
8 ms |
14428 KB |
Output is correct |
18 |
Correct |
8 ms |
14428 KB |
Output is correct |
19 |
Correct |
225 ms |
51648 KB |
Output is correct |
20 |
Correct |
188 ms |
51892 KB |
Output is correct |
21 |
Correct |
171 ms |
51956 KB |
Output is correct |
22 |
Correct |
183 ms |
48752 KB |
Output is correct |
23 |
Correct |
219 ms |
61620 KB |
Output is correct |
24 |
Correct |
168 ms |
49748 KB |
Output is correct |
25 |
Correct |
123 ms |
37204 KB |
Output is correct |
26 |
Correct |
64 ms |
38992 KB |
Output is correct |
27 |
Correct |
268 ms |
57088 KB |
Output is correct |
28 |
Correct |
248 ms |
63776 KB |
Output is correct |
29 |
Correct |
259 ms |
63792 KB |
Output is correct |
30 |
Correct |
222 ms |
57684 KB |
Output is correct |
31 |
Correct |
247 ms |
57680 KB |
Output is correct |
32 |
Correct |
364 ms |
57448 KB |
Output is correct |
33 |
Correct |
312 ms |
72788 KB |
Output is correct |
34 |
Correct |
307 ms |
71504 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
14424 KB |
Output is correct |
2 |
Correct |
7 ms |
14428 KB |
Output is correct |
3 |
Correct |
7 ms |
14428 KB |
Output is correct |
4 |
Correct |
9 ms |
14428 KB |
Output is correct |
5 |
Correct |
9 ms |
14424 KB |
Output is correct |
6 |
Correct |
8 ms |
14428 KB |
Output is correct |
7 |
Correct |
7 ms |
14424 KB |
Output is correct |
8 |
Correct |
11 ms |
14428 KB |
Output is correct |
9 |
Correct |
10 ms |
14428 KB |
Output is correct |
10 |
Correct |
9 ms |
14428 KB |
Output is correct |
11 |
Correct |
7 ms |
14428 KB |
Output is correct |
12 |
Correct |
9 ms |
14428 KB |
Output is correct |
13 |
Correct |
8 ms |
14428 KB |
Output is correct |
14 |
Correct |
7 ms |
14484 KB |
Output is correct |
15 |
Correct |
8 ms |
14428 KB |
Output is correct |
16 |
Correct |
8 ms |
14428 KB |
Output is correct |
17 |
Correct |
8 ms |
14428 KB |
Output is correct |
18 |
Correct |
8 ms |
14428 KB |
Output is correct |
19 |
Correct |
7 ms |
14424 KB |
Output is correct |
20 |
Correct |
8 ms |
14428 KB |
Output is correct |
21 |
Correct |
9 ms |
14684 KB |
Output is correct |
22 |
Correct |
9 ms |
14824 KB |
Output is correct |
23 |
Correct |
9 ms |
14680 KB |
Output is correct |
24 |
Correct |
9 ms |
14696 KB |
Output is correct |
25 |
Correct |
8 ms |
14684 KB |
Output is correct |
26 |
Correct |
9 ms |
14680 KB |
Output is correct |
27 |
Correct |
11 ms |
14684 KB |
Output is correct |
28 |
Correct |
11 ms |
14684 KB |
Output is correct |
29 |
Correct |
8 ms |
14884 KB |
Output is correct |
30 |
Correct |
9 ms |
14684 KB |
Output is correct |
31 |
Correct |
8 ms |
14684 KB |
Output is correct |
32 |
Correct |
13 ms |
14684 KB |
Output is correct |
33 |
Correct |
10 ms |
14684 KB |
Output is correct |
34 |
Correct |
9 ms |
14684 KB |
Output is correct |
35 |
Correct |
11 ms |
14684 KB |
Output is correct |
36 |
Correct |
9 ms |
14684 KB |
Output is correct |
37 |
Correct |
9 ms |
14680 KB |
Output is correct |
38 |
Correct |
9 ms |
14684 KB |
Output is correct |
39 |
Correct |
225 ms |
51648 KB |
Output is correct |
40 |
Correct |
188 ms |
51892 KB |
Output is correct |
41 |
Correct |
171 ms |
51956 KB |
Output is correct |
42 |
Correct |
183 ms |
48752 KB |
Output is correct |
43 |
Correct |
219 ms |
61620 KB |
Output is correct |
44 |
Correct |
168 ms |
49748 KB |
Output is correct |
45 |
Correct |
123 ms |
37204 KB |
Output is correct |
46 |
Correct |
64 ms |
38992 KB |
Output is correct |
47 |
Correct |
268 ms |
57088 KB |
Output is correct |
48 |
Correct |
248 ms |
63776 KB |
Output is correct |
49 |
Correct |
259 ms |
63792 KB |
Output is correct |
50 |
Correct |
222 ms |
57684 KB |
Output is correct |
51 |
Correct |
247 ms |
57680 KB |
Output is correct |
52 |
Correct |
364 ms |
57448 KB |
Output is correct |
53 |
Correct |
312 ms |
72788 KB |
Output is correct |
54 |
Correct |
307 ms |
71504 KB |
Output is correct |
55 |
Correct |
19 ms |
17244 KB |
Output is correct |
56 |
Correct |
19 ms |
17500 KB |
Output is correct |
57 |
Correct |
164 ms |
61780 KB |
Output is correct |
58 |
Correct |
74 ms |
31432 KB |
Output is correct |
59 |
Correct |
67 ms |
39252 KB |
Output is correct |
60 |
Correct |
204 ms |
63608 KB |
Output is correct |
61 |
Correct |
274 ms |
56912 KB |
Output is correct |
62 |
Correct |
236 ms |
57600 KB |
Output is correct |
63 |
Correct |
376 ms |
57408 KB |
Output is correct |
64 |
Correct |
431 ms |
90076 KB |
Output is correct |
65 |
Correct |
434 ms |
84556 KB |
Output is correct |
66 |
Correct |
285 ms |
59984 KB |
Output is correct |
67 |
Correct |
242 ms |
50112 KB |
Output is correct |
68 |
Correct |
362 ms |
57560 KB |
Output is correct |
69 |
Correct |
405 ms |
59952 KB |
Output is correct |
70 |
Correct |
319 ms |
56144 KB |
Output is correct |