#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e5 + 25;
int t[MAXN], n, m;
array <int, 3> edges[MAXN];
int deg[MAXN];
vector <int> sub[MAXN]; int par[MAXN];
bool ok[MAXN];
vector <array <int, 3>> times[MAXN];
void init (int N, int M, vector <int> u, vector <int> v, vector <int> w) {
n = N; m = M;
for (int i = 0; i < m; i++) edges[i] = {u[i], v[i], w[i]};
for (int i = 0; i < m; i++) t[i] = i;
sort(t, t + m, [&] (int &x, int &y) { return edges[x][2] < edges[y][2]; });
for (int i = 0; i < n; i++) {
sub[i].push_back(i);
par[i] = i;
times[i].push_back({-1, i, 0});
}
for (int i = 0; i < m; i++) {
int a = edges[t[i]][0], b = edges[t[i]][1];
if (par[a] == par[b]) {
if (ok[par[a]]) {
deg[a]++; deg[b]++;
continue;
}
ok[par[a]] = 1;
for (auto j : sub[par[a]]) {
times[j].push_back({i, par[a], 1});
}
deg[a]++; deg[b]++;
continue;
}
if (sub[par[a]].size() > sub[par[b]].size()) swap(a, b);
bool flag = ok[par[a]] || ok[par[b]];
flag |= deg[a] > 1 || deg[b] > 1;
if (!flag) {
int l = par[a];
for (auto j : sub[l]) {
times[j].push_back({i, par[b], 0});
par[j] = par[b];
sub[par[b]].push_back(j);
}
sub[l].clear();
deg[a]++; deg[b]++;
continue;
}
if (!ok[par[b]]) {
ok[par[b]] = 1;
for (auto j : sub[par[b]]) {
times[j].push_back({i, par[b], 1});
}
}
int l = par[a];
for (auto j : sub[l]) {
times[j].push_back({i, par[b], 1});
par[j] = par[b];
sub[par[b]].push_back(j);
}
sub[l].clear();
deg[a]++; deg[b]++;
}
}
int getMinimumFuelCapacity (int x, int y) {
int l = 0, r = m - 1, ans = -1;
while (l <= r) {
int mid = (l + r) / 2;
array <int, 3> ff = {mid + 1, (int)-1e9, (int)-1e9};
auto g = lower_bound(times[x].begin(), times[x].end(), ff) - times[x].begin();
auto h = lower_bound(times[y].begin(), times[y].end(), ff) - times[y].begin();
g--; h--;
if (times[x][g][1] != times[y][h][1]) {
l = mid + 1; continue;
}
if (!times[x][g][2] || !times[y][h][2]) {
l = mid + 1;
} else {
r = mid - 1; ans = mid;
}
}
return ans == -1 ? -1 : edges[t[ans]][2];
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
6748 KB |
Output is correct |
2 |
Correct |
2 ms |
6748 KB |
Output is correct |
3 |
Correct |
1 ms |
6748 KB |
Output is correct |
4 |
Correct |
1 ms |
6748 KB |
Output is correct |
5 |
Correct |
2 ms |
6904 KB |
Output is correct |
6 |
Correct |
2 ms |
6744 KB |
Output is correct |
7 |
Correct |
2 ms |
6744 KB |
Output is correct |
8 |
Correct |
2 ms |
6744 KB |
Output is correct |
9 |
Correct |
77 ms |
25380 KB |
Output is correct |
10 |
Correct |
108 ms |
29352 KB |
Output is correct |
11 |
Correct |
149 ms |
28920 KB |
Output is correct |
12 |
Correct |
108 ms |
30240 KB |
Output is correct |
13 |
Correct |
96 ms |
19784 KB |
Output is correct |
14 |
Correct |
105 ms |
25264 KB |
Output is correct |
15 |
Correct |
243 ms |
34144 KB |
Output is correct |
16 |
Correct |
266 ms |
33404 KB |
Output is correct |
17 |
Correct |
328 ms |
35236 KB |
Output is correct |
18 |
Correct |
187 ms |
24164 KB |
Output is correct |
19 |
Correct |
115 ms |
15100 KB |
Output is correct |
20 |
Correct |
263 ms |
35272 KB |
Output is correct |
21 |
Correct |
248 ms |
34692 KB |
Output is correct |
22 |
Correct |
273 ms |
36272 KB |
Output is correct |
23 |
Correct |
214 ms |
25984 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
6748 KB |
Output is correct |
2 |
Correct |
2 ms |
6748 KB |
Output is correct |
3 |
Correct |
166 ms |
19164 KB |
Output is correct |
4 |
Correct |
156 ms |
23360 KB |
Output is correct |
5 |
Correct |
158 ms |
23404 KB |
Output is correct |
6 |
Correct |
170 ms |
23344 KB |
Output is correct |
7 |
Correct |
156 ms |
23372 KB |
Output is correct |
8 |
Correct |
146 ms |
22908 KB |
Output is correct |
9 |
Correct |
152 ms |
23196 KB |
Output is correct |
10 |
Correct |
153 ms |
22920 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
6748 KB |
Output is correct |
2 |
Correct |
2 ms |
6748 KB |
Output is correct |
3 |
Correct |
1 ms |
6748 KB |
Output is correct |
4 |
Correct |
1 ms |
6748 KB |
Output is correct |
5 |
Correct |
2 ms |
6904 KB |
Output is correct |
6 |
Correct |
2 ms |
6744 KB |
Output is correct |
7 |
Correct |
2 ms |
6744 KB |
Output is correct |
8 |
Correct |
2 ms |
6744 KB |
Output is correct |
9 |
Correct |
2 ms |
6744 KB |
Output is correct |
10 |
Correct |
3 ms |
6748 KB |
Output is correct |
11 |
Correct |
2 ms |
6748 KB |
Output is correct |
12 |
Correct |
2 ms |
6748 KB |
Output is correct |
13 |
Correct |
2 ms |
6748 KB |
Output is correct |
14 |
Correct |
2 ms |
6748 KB |
Output is correct |
15 |
Correct |
2 ms |
6748 KB |
Output is correct |
16 |
Correct |
2 ms |
6744 KB |
Output is correct |
17 |
Correct |
2 ms |
6748 KB |
Output is correct |
18 |
Correct |
2 ms |
6748 KB |
Output is correct |
19 |
Correct |
2 ms |
6748 KB |
Output is correct |
20 |
Correct |
3 ms |
6748 KB |
Output is correct |
21 |
Correct |
2 ms |
6748 KB |
Output is correct |
22 |
Correct |
2 ms |
6744 KB |
Output is correct |
23 |
Correct |
2 ms |
6836 KB |
Output is correct |
24 |
Correct |
2 ms |
7000 KB |
Output is correct |
25 |
Correct |
2 ms |
6748 KB |
Output is correct |
26 |
Correct |
2 ms |
7000 KB |
Output is correct |
27 |
Correct |
2 ms |
6748 KB |
Output is correct |
28 |
Correct |
2 ms |
6744 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
6744 KB |
Output is correct |
2 |
Correct |
1 ms |
6748 KB |
Output is correct |
3 |
Correct |
2 ms |
6748 KB |
Output is correct |
4 |
Correct |
1 ms |
6748 KB |
Output is correct |
5 |
Correct |
1 ms |
6748 KB |
Output is correct |
6 |
Correct |
2 ms |
6904 KB |
Output is correct |
7 |
Correct |
2 ms |
6744 KB |
Output is correct |
8 |
Correct |
2 ms |
6744 KB |
Output is correct |
9 |
Correct |
2 ms |
6744 KB |
Output is correct |
10 |
Correct |
77 ms |
25380 KB |
Output is correct |
11 |
Correct |
108 ms |
29352 KB |
Output is correct |
12 |
Correct |
149 ms |
28920 KB |
Output is correct |
13 |
Correct |
108 ms |
30240 KB |
Output is correct |
14 |
Correct |
96 ms |
19784 KB |
Output is correct |
15 |
Correct |
3 ms |
6748 KB |
Output is correct |
16 |
Correct |
2 ms |
6748 KB |
Output is correct |
17 |
Correct |
2 ms |
6748 KB |
Output is correct |
18 |
Correct |
2 ms |
6748 KB |
Output is correct |
19 |
Correct |
2 ms |
6748 KB |
Output is correct |
20 |
Correct |
2 ms |
6748 KB |
Output is correct |
21 |
Correct |
2 ms |
6744 KB |
Output is correct |
22 |
Correct |
2 ms |
6748 KB |
Output is correct |
23 |
Correct |
2 ms |
6748 KB |
Output is correct |
24 |
Correct |
2 ms |
6748 KB |
Output is correct |
25 |
Correct |
3 ms |
6748 KB |
Output is correct |
26 |
Correct |
2 ms |
6748 KB |
Output is correct |
27 |
Correct |
2 ms |
6744 KB |
Output is correct |
28 |
Correct |
2 ms |
6836 KB |
Output is correct |
29 |
Correct |
2 ms |
7000 KB |
Output is correct |
30 |
Correct |
2 ms |
6748 KB |
Output is correct |
31 |
Correct |
2 ms |
7000 KB |
Output is correct |
32 |
Correct |
2 ms |
6748 KB |
Output is correct |
33 |
Correct |
2 ms |
6744 KB |
Output is correct |
34 |
Correct |
11 ms |
9304 KB |
Output is correct |
35 |
Correct |
113 ms |
30584 KB |
Output is correct |
36 |
Correct |
105 ms |
29828 KB |
Output is correct |
37 |
Correct |
133 ms |
29388 KB |
Output is correct |
38 |
Correct |
109 ms |
28532 KB |
Output is correct |
39 |
Correct |
138 ms |
28104 KB |
Output is correct |
40 |
Correct |
107 ms |
25720 KB |
Output is correct |
41 |
Correct |
116 ms |
33096 KB |
Output is correct |
42 |
Correct |
123 ms |
32164 KB |
Output is correct |
43 |
Correct |
64 ms |
18652 KB |
Output is correct |
44 |
Correct |
99 ms |
27984 KB |
Output is correct |
45 |
Runtime error |
42 ms |
22056 KB |
Execution killed with signal 11 |
46 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
6748 KB |
Output is correct |
2 |
Correct |
2 ms |
6748 KB |
Output is correct |
3 |
Correct |
1 ms |
6748 KB |
Output is correct |
4 |
Correct |
1 ms |
6748 KB |
Output is correct |
5 |
Correct |
2 ms |
6904 KB |
Output is correct |
6 |
Correct |
2 ms |
6744 KB |
Output is correct |
7 |
Correct |
2 ms |
6744 KB |
Output is correct |
8 |
Correct |
2 ms |
6744 KB |
Output is correct |
9 |
Correct |
77 ms |
25380 KB |
Output is correct |
10 |
Correct |
108 ms |
29352 KB |
Output is correct |
11 |
Correct |
149 ms |
28920 KB |
Output is correct |
12 |
Correct |
108 ms |
30240 KB |
Output is correct |
13 |
Correct |
96 ms |
19784 KB |
Output is correct |
14 |
Correct |
105 ms |
25264 KB |
Output is correct |
15 |
Correct |
243 ms |
34144 KB |
Output is correct |
16 |
Correct |
266 ms |
33404 KB |
Output is correct |
17 |
Correct |
328 ms |
35236 KB |
Output is correct |
18 |
Correct |
187 ms |
24164 KB |
Output is correct |
19 |
Correct |
166 ms |
19164 KB |
Output is correct |
20 |
Correct |
156 ms |
23360 KB |
Output is correct |
21 |
Correct |
158 ms |
23404 KB |
Output is correct |
22 |
Correct |
170 ms |
23344 KB |
Output is correct |
23 |
Correct |
156 ms |
23372 KB |
Output is correct |
24 |
Correct |
146 ms |
22908 KB |
Output is correct |
25 |
Correct |
152 ms |
23196 KB |
Output is correct |
26 |
Correct |
153 ms |
22920 KB |
Output is correct |
27 |
Correct |
3 ms |
6748 KB |
Output is correct |
28 |
Correct |
2 ms |
6748 KB |
Output is correct |
29 |
Correct |
2 ms |
6748 KB |
Output is correct |
30 |
Correct |
2 ms |
6748 KB |
Output is correct |
31 |
Correct |
2 ms |
6748 KB |
Output is correct |
32 |
Correct |
2 ms |
6748 KB |
Output is correct |
33 |
Correct |
2 ms |
6744 KB |
Output is correct |
34 |
Correct |
2 ms |
6748 KB |
Output is correct |
35 |
Correct |
2 ms |
6748 KB |
Output is correct |
36 |
Correct |
11 ms |
9304 KB |
Output is correct |
37 |
Correct |
113 ms |
30584 KB |
Output is correct |
38 |
Correct |
105 ms |
29828 KB |
Output is correct |
39 |
Correct |
133 ms |
29388 KB |
Output is correct |
40 |
Correct |
109 ms |
28532 KB |
Output is correct |
41 |
Correct |
138 ms |
28104 KB |
Output is correct |
42 |
Correct |
107 ms |
25720 KB |
Output is correct |
43 |
Correct |
116 ms |
33096 KB |
Output is correct |
44 |
Correct |
123 ms |
32164 KB |
Output is correct |
45 |
Correct |
64 ms |
18652 KB |
Output is correct |
46 |
Correct |
99 ms |
27984 KB |
Output is correct |
47 |
Correct |
22 ms |
10076 KB |
Output is correct |
48 |
Correct |
308 ms |
37204 KB |
Output is correct |
49 |
Correct |
259 ms |
36404 KB |
Output is correct |
50 |
Correct |
256 ms |
36404 KB |
Output is correct |
51 |
Correct |
245 ms |
35600 KB |
Output is correct |
52 |
Correct |
262 ms |
33536 KB |
Output is correct |
53 |
Correct |
219 ms |
27324 KB |
Output is correct |
54 |
Correct |
259 ms |
39480 KB |
Output is correct |
55 |
Correct |
303 ms |
39272 KB |
Output is correct |
56 |
Correct |
160 ms |
26324 KB |
Output is correct |
57 |
Correct |
268 ms |
35120 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
6744 KB |
Output is correct |
2 |
Correct |
1 ms |
6748 KB |
Output is correct |
3 |
Correct |
2 ms |
6748 KB |
Output is correct |
4 |
Correct |
1 ms |
6748 KB |
Output is correct |
5 |
Correct |
1 ms |
6748 KB |
Output is correct |
6 |
Correct |
2 ms |
6904 KB |
Output is correct |
7 |
Correct |
2 ms |
6744 KB |
Output is correct |
8 |
Correct |
2 ms |
6744 KB |
Output is correct |
9 |
Correct |
2 ms |
6744 KB |
Output is correct |
10 |
Correct |
77 ms |
25380 KB |
Output is correct |
11 |
Correct |
108 ms |
29352 KB |
Output is correct |
12 |
Correct |
149 ms |
28920 KB |
Output is correct |
13 |
Correct |
108 ms |
30240 KB |
Output is correct |
14 |
Correct |
96 ms |
19784 KB |
Output is correct |
15 |
Correct |
105 ms |
25264 KB |
Output is correct |
16 |
Correct |
243 ms |
34144 KB |
Output is correct |
17 |
Correct |
266 ms |
33404 KB |
Output is correct |
18 |
Correct |
328 ms |
35236 KB |
Output is correct |
19 |
Correct |
187 ms |
24164 KB |
Output is correct |
20 |
Correct |
166 ms |
19164 KB |
Output is correct |
21 |
Correct |
156 ms |
23360 KB |
Output is correct |
22 |
Correct |
158 ms |
23404 KB |
Output is correct |
23 |
Correct |
170 ms |
23344 KB |
Output is correct |
24 |
Correct |
156 ms |
23372 KB |
Output is correct |
25 |
Correct |
146 ms |
22908 KB |
Output is correct |
26 |
Correct |
152 ms |
23196 KB |
Output is correct |
27 |
Correct |
153 ms |
22920 KB |
Output is correct |
28 |
Correct |
3 ms |
6748 KB |
Output is correct |
29 |
Correct |
2 ms |
6748 KB |
Output is correct |
30 |
Correct |
2 ms |
6748 KB |
Output is correct |
31 |
Correct |
2 ms |
6748 KB |
Output is correct |
32 |
Correct |
2 ms |
6748 KB |
Output is correct |
33 |
Correct |
2 ms |
6748 KB |
Output is correct |
34 |
Correct |
2 ms |
6744 KB |
Output is correct |
35 |
Correct |
2 ms |
6748 KB |
Output is correct |
36 |
Correct |
2 ms |
6748 KB |
Output is correct |
37 |
Correct |
11 ms |
9304 KB |
Output is correct |
38 |
Correct |
113 ms |
30584 KB |
Output is correct |
39 |
Correct |
105 ms |
29828 KB |
Output is correct |
40 |
Correct |
133 ms |
29388 KB |
Output is correct |
41 |
Correct |
109 ms |
28532 KB |
Output is correct |
42 |
Correct |
138 ms |
28104 KB |
Output is correct |
43 |
Correct |
107 ms |
25720 KB |
Output is correct |
44 |
Correct |
116 ms |
33096 KB |
Output is correct |
45 |
Correct |
123 ms |
32164 KB |
Output is correct |
46 |
Correct |
64 ms |
18652 KB |
Output is correct |
47 |
Correct |
99 ms |
27984 KB |
Output is correct |
48 |
Correct |
22 ms |
10076 KB |
Output is correct |
49 |
Correct |
308 ms |
37204 KB |
Output is correct |
50 |
Correct |
259 ms |
36404 KB |
Output is correct |
51 |
Correct |
256 ms |
36404 KB |
Output is correct |
52 |
Correct |
245 ms |
35600 KB |
Output is correct |
53 |
Correct |
262 ms |
33536 KB |
Output is correct |
54 |
Correct |
219 ms |
27324 KB |
Output is correct |
55 |
Correct |
259 ms |
39480 KB |
Output is correct |
56 |
Correct |
303 ms |
39272 KB |
Output is correct |
57 |
Correct |
160 ms |
26324 KB |
Output is correct |
58 |
Correct |
268 ms |
35120 KB |
Output is correct |
59 |
Correct |
115 ms |
15100 KB |
Output is correct |
60 |
Correct |
263 ms |
35272 KB |
Output is correct |
61 |
Correct |
248 ms |
34692 KB |
Output is correct |
62 |
Correct |
273 ms |
36272 KB |
Output is correct |
63 |
Correct |
214 ms |
25984 KB |
Output is correct |
64 |
Correct |
2 ms |
6748 KB |
Output is correct |
65 |
Correct |
3 ms |
6748 KB |
Output is correct |
66 |
Correct |
2 ms |
6748 KB |
Output is correct |
67 |
Correct |
2 ms |
6744 KB |
Output is correct |
68 |
Correct |
2 ms |
6836 KB |
Output is correct |
69 |
Correct |
2 ms |
7000 KB |
Output is correct |
70 |
Correct |
2 ms |
6748 KB |
Output is correct |
71 |
Correct |
2 ms |
7000 KB |
Output is correct |
72 |
Correct |
2 ms |
6748 KB |
Output is correct |
73 |
Correct |
2 ms |
6744 KB |
Output is correct |
74 |
Runtime error |
42 ms |
22056 KB |
Execution killed with signal 11 |
75 |
Halted |
0 ms |
0 KB |
- |