#include "swap.h"
#include <cstring>
#include <vector>
const int N = 100000, M = 200000, INF = 0x3f3f3f3f;
int min(int a, int b) { return a < b ? a : b; }
int max(int a, int b) { return a > b ? a : b; }
unsigned int X = 12345;
int rand_() {
return (X *= 3) >> 1;
}
int ww[M];
void sort(int *hh, int l, int r) {
while (l < r) {
int i = l, j = l, k = r, h = hh[l + rand_() % (r - l)], tmp;
while (j < k)
if (ww[hh[j]] == ww[h])
j++;
else if (ww[hh[j]] < ww[h]) {
tmp = hh[i], hh[i] = hh[j], hh[j] = tmp;
i++, j++;
} else {
k--;
tmp = hh[j], hh[j] = hh[k], hh[k] = tmp;
}
sort(hh, l, i);
l = k;
}
}
int ds[N], ww_[N], ww1[N];
int find(int i) {
return ds[i] < 0 ? i : find(ds[i]);
}
void join(int i, int j, int w, int special) {
i = find(i);
j = find(j);
if (i == j) {
ww1[i] = min(ww1[i], w);
return;
}
if (ds[i] > ds[j]) {
ds[i] = j, ww_[i] = w;
ww1[j] = min(ww1[j], ww1[i]);
if (special)
ww1[j] = min(ww1[j], w);
} else {
if (ds[i] == ds[j])
ds[i]--;
ds[j] = i, ww_[j] = w;
ww1[i] = min(ww1[i], ww1[j]);
if (special)
ww1[i] = min(ww1[i], w);
}
}
int n, m;
void init(int n_, int m_, std::vector<int> ii, std::vector<int> jj, std::vector<int> WW) {
static int hh[M], dd[N];
int h;
n = n_, m = m_;
for (h = 0; h < m; h++)
ww[h] = WW[h], hh[h] = h;
sort(hh, 0, m);
memset(dd, 0, n * sizeof *dd);
memset(ds, -1, n * sizeof *ds);
memset(ww_, 0x3f, n * sizeof *ww_);
memset(ww1, 0x3f, n * sizeof *ww1);
for (h = 0; h < m; h++) {
int i = ii[hh[h]], j = jj[hh[h]], w = ww[hh[h]];
dd[i]++, dd[j]++;
join(i, j, w, dd[i] > 2 || dd[j] > 2);
}
}
int getMinimumFuelCapacity(int i, int j) {
long long w1 = 0;
while (i != j)
if (ww_[i] < ww_[j])
w1 = ww_[i], i = ds[i];
else
w1 = ww_[j], j = ds[j];
while (i >= 0) {
if (ww1[i] != INF)
return max(w1, ww1[i]);
w1 = ww_[i];
i = ds[i];
}
return -1;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
2 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
44 ms |
3948 KB |
Output is correct |
10 |
Correct |
55 ms |
4972 KB |
Output is correct |
11 |
Correct |
54 ms |
4644 KB |
Output is correct |
12 |
Correct |
58 ms |
4996 KB |
Output is correct |
13 |
Correct |
55 ms |
4972 KB |
Output is correct |
14 |
Correct |
51 ms |
4224 KB |
Output is correct |
15 |
Correct |
142 ms |
6644 KB |
Output is correct |
16 |
Correct |
139 ms |
6552 KB |
Output is correct |
17 |
Correct |
143 ms |
6864 KB |
Output is correct |
18 |
Correct |
123 ms |
6864 KB |
Output is correct |
19 |
Correct |
83 ms |
4532 KB |
Output is correct |
20 |
Correct |
140 ms |
7784 KB |
Output is correct |
21 |
Correct |
143 ms |
7972 KB |
Output is correct |
22 |
Correct |
156 ms |
8272 KB |
Output is correct |
23 |
Correct |
129 ms |
8148 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
120 ms |
7904 KB |
Output is correct |
4 |
Correct |
116 ms |
7892 KB |
Output is correct |
5 |
Correct |
120 ms |
8068 KB |
Output is correct |
6 |
Correct |
130 ms |
7892 KB |
Output is correct |
7 |
Correct |
122 ms |
8040 KB |
Output is correct |
8 |
Correct |
116 ms |
7832 KB |
Output is correct |
9 |
Correct |
117 ms |
7860 KB |
Output is correct |
10 |
Correct |
117 ms |
7844 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
2 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
1 ms |
364 KB |
Output is correct |
12 |
Correct |
2 ms |
364 KB |
Output is correct |
13 |
Correct |
1 ms |
364 KB |
Output is correct |
14 |
Correct |
1 ms |
364 KB |
Output is correct |
15 |
Correct |
1 ms |
364 KB |
Output is correct |
16 |
Correct |
1 ms |
364 KB |
Output is correct |
17 |
Correct |
1 ms |
364 KB |
Output is correct |
18 |
Correct |
1 ms |
364 KB |
Output is correct |
19 |
Correct |
1 ms |
364 KB |
Output is correct |
20 |
Correct |
1 ms |
364 KB |
Output is correct |
21 |
Correct |
2 ms |
364 KB |
Output is correct |
22 |
Correct |
2 ms |
364 KB |
Output is correct |
23 |
Correct |
1 ms |
364 KB |
Output is correct |
24 |
Incorrect |
2 ms |
364 KB |
Output isn't correct |
25 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
2 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
44 ms |
3948 KB |
Output is correct |
11 |
Correct |
55 ms |
4972 KB |
Output is correct |
12 |
Correct |
54 ms |
4644 KB |
Output is correct |
13 |
Correct |
58 ms |
4996 KB |
Output is correct |
14 |
Correct |
55 ms |
4972 KB |
Output is correct |
15 |
Correct |
1 ms |
364 KB |
Output is correct |
16 |
Correct |
1 ms |
364 KB |
Output is correct |
17 |
Correct |
2 ms |
364 KB |
Output is correct |
18 |
Correct |
1 ms |
364 KB |
Output is correct |
19 |
Correct |
1 ms |
364 KB |
Output is correct |
20 |
Correct |
1 ms |
364 KB |
Output is correct |
21 |
Correct |
1 ms |
364 KB |
Output is correct |
22 |
Correct |
1 ms |
364 KB |
Output is correct |
23 |
Correct |
1 ms |
364 KB |
Output is correct |
24 |
Correct |
1 ms |
364 KB |
Output is correct |
25 |
Correct |
1 ms |
364 KB |
Output is correct |
26 |
Correct |
2 ms |
364 KB |
Output is correct |
27 |
Correct |
2 ms |
364 KB |
Output is correct |
28 |
Correct |
1 ms |
364 KB |
Output is correct |
29 |
Incorrect |
2 ms |
364 KB |
Output isn't correct |
30 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
2 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
44 ms |
3948 KB |
Output is correct |
10 |
Correct |
55 ms |
4972 KB |
Output is correct |
11 |
Correct |
54 ms |
4644 KB |
Output is correct |
12 |
Correct |
58 ms |
4996 KB |
Output is correct |
13 |
Correct |
55 ms |
4972 KB |
Output is correct |
14 |
Correct |
51 ms |
4224 KB |
Output is correct |
15 |
Correct |
142 ms |
6644 KB |
Output is correct |
16 |
Correct |
139 ms |
6552 KB |
Output is correct |
17 |
Correct |
143 ms |
6864 KB |
Output is correct |
18 |
Correct |
123 ms |
6864 KB |
Output is correct |
19 |
Correct |
120 ms |
7904 KB |
Output is correct |
20 |
Correct |
116 ms |
7892 KB |
Output is correct |
21 |
Correct |
120 ms |
8068 KB |
Output is correct |
22 |
Correct |
130 ms |
7892 KB |
Output is correct |
23 |
Correct |
122 ms |
8040 KB |
Output is correct |
24 |
Correct |
116 ms |
7832 KB |
Output is correct |
25 |
Correct |
117 ms |
7860 KB |
Output is correct |
26 |
Correct |
117 ms |
7844 KB |
Output is correct |
27 |
Correct |
1 ms |
364 KB |
Output is correct |
28 |
Correct |
1 ms |
364 KB |
Output is correct |
29 |
Correct |
2 ms |
364 KB |
Output is correct |
30 |
Correct |
1 ms |
364 KB |
Output is correct |
31 |
Correct |
1 ms |
364 KB |
Output is correct |
32 |
Correct |
1 ms |
364 KB |
Output is correct |
33 |
Correct |
1 ms |
364 KB |
Output is correct |
34 |
Correct |
1 ms |
364 KB |
Output is correct |
35 |
Correct |
1 ms |
364 KB |
Output is correct |
36 |
Correct |
8 ms |
1004 KB |
Output is correct |
37 |
Correct |
57 ms |
4972 KB |
Output is correct |
38 |
Correct |
53 ms |
4972 KB |
Output is correct |
39 |
Correct |
62 ms |
4972 KB |
Output is correct |
40 |
Correct |
54 ms |
5028 KB |
Output is correct |
41 |
Correct |
52 ms |
4972 KB |
Output is correct |
42 |
Correct |
48 ms |
4588 KB |
Output is correct |
43 |
Incorrect |
57 ms |
5100 KB |
Output isn't correct |
44 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
2 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
44 ms |
3948 KB |
Output is correct |
11 |
Correct |
55 ms |
4972 KB |
Output is correct |
12 |
Correct |
54 ms |
4644 KB |
Output is correct |
13 |
Correct |
58 ms |
4996 KB |
Output is correct |
14 |
Correct |
55 ms |
4972 KB |
Output is correct |
15 |
Correct |
51 ms |
4224 KB |
Output is correct |
16 |
Correct |
142 ms |
6644 KB |
Output is correct |
17 |
Correct |
139 ms |
6552 KB |
Output is correct |
18 |
Correct |
143 ms |
6864 KB |
Output is correct |
19 |
Correct |
123 ms |
6864 KB |
Output is correct |
20 |
Correct |
120 ms |
7904 KB |
Output is correct |
21 |
Correct |
116 ms |
7892 KB |
Output is correct |
22 |
Correct |
120 ms |
8068 KB |
Output is correct |
23 |
Correct |
130 ms |
7892 KB |
Output is correct |
24 |
Correct |
122 ms |
8040 KB |
Output is correct |
25 |
Correct |
116 ms |
7832 KB |
Output is correct |
26 |
Correct |
117 ms |
7860 KB |
Output is correct |
27 |
Correct |
117 ms |
7844 KB |
Output is correct |
28 |
Correct |
1 ms |
364 KB |
Output is correct |
29 |
Correct |
1 ms |
364 KB |
Output is correct |
30 |
Correct |
2 ms |
364 KB |
Output is correct |
31 |
Correct |
1 ms |
364 KB |
Output is correct |
32 |
Correct |
1 ms |
364 KB |
Output is correct |
33 |
Correct |
1 ms |
364 KB |
Output is correct |
34 |
Correct |
1 ms |
364 KB |
Output is correct |
35 |
Correct |
1 ms |
364 KB |
Output is correct |
36 |
Correct |
1 ms |
364 KB |
Output is correct |
37 |
Correct |
8 ms |
1004 KB |
Output is correct |
38 |
Correct |
57 ms |
4972 KB |
Output is correct |
39 |
Correct |
53 ms |
4972 KB |
Output is correct |
40 |
Correct |
62 ms |
4972 KB |
Output is correct |
41 |
Correct |
54 ms |
5028 KB |
Output is correct |
42 |
Correct |
52 ms |
4972 KB |
Output is correct |
43 |
Correct |
48 ms |
4588 KB |
Output is correct |
44 |
Incorrect |
57 ms |
5100 KB |
Output isn't correct |
45 |
Halted |
0 ms |
0 KB |
- |