#include "swap.h"
#include <iostream>
#include <vector>
#include <algorithm>
#include <climits>
using namespace std;
int n, m;
vector<int> u_, v_, w, ver, var, par, P, p, her, sizes;
int get(int u)
{
if (u == par[u]) return u;
return get(par[u]);
}
void union_chains(int u, int v, int w)
{
int a = get(u), b = get(v);
if (a == b)
{
P[a] = min(P[a], w);
return;
}
if (sizes[a] < sizes[b]) swap(a, b), swap(u, v);
sizes[a] += sizes[b];
par[v] = par[u];
her[v] = w;
if (u == ver[a] && v == ver[b]) ver[a] = var[b];
else if (u == ver[a] && v == var[b]) ver[a] = ver[b];
else if (u == var[a] && v == ver[b]) var[a] = var[b];
else if (u == var[a] && v == var[b]) var[a] = ver[b];
else ver[a] = -1, var[a] = -1, P[a] = min(P[a], w);
}
int go(int u, int w)
{
if (par[u] == u || her[u] > w) return u;
return par[u] = go(par[u], w);
}
void init(int N, int M, vector<int> U, vector<int> V, vector<int> W) {
n = N, m = M;
vector<pair<int, pair<int, int>>> kox;
for (int i = 0; i < m; i++) kox.push_back({ W[i], {U[i], V[i]} });
sort(kox.begin(), kox.end());
ver = var = par = sizes = P = her = p = vector<int>(n);
for (int i = 0; i < n; i++) ver[i] = var[i] = par[i] = p[i] = i, sizes[i] = 1, her[i] = P[i] = INT_MAX;
for (int i = 0; i < m; i++)
{
int u = kox[i].second.first, v = kox[i].second.second;
union_chains(u, v, kox[i].first);
}
}
int getMinimumFuelCapacity(int X, int Y) {
long long l = 0, r = 2e9;
while (l + 1 < r)
{
int mij = l + (r - l) / 2;
int a = go(X, mij), b = go(Y, mij);
if (a == b && P[get(a)] <= mij) r = mij;
else l = mij;
}
return r == 2e9 ? -1 : r;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
2 ms |
340 KB |
Output is correct |
9 |
Correct |
40 ms |
5148 KB |
Output is correct |
10 |
Correct |
41 ms |
6208 KB |
Output is correct |
11 |
Correct |
42 ms |
6224 KB |
Output is correct |
12 |
Correct |
43 ms |
6464 KB |
Output is correct |
13 |
Correct |
45 ms |
6456 KB |
Output is correct |
14 |
Correct |
41 ms |
5260 KB |
Output is correct |
15 |
Correct |
134 ms |
7844 KB |
Output is correct |
16 |
Correct |
119 ms |
7692 KB |
Output is correct |
17 |
Correct |
126 ms |
8020 KB |
Output is correct |
18 |
Correct |
135 ms |
8020 KB |
Output is correct |
19 |
Incorrect |
72 ms |
3412 KB |
Output isn't correct |
20 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
143 ms |
8028 KB |
Output is correct |
4 |
Correct |
154 ms |
8196 KB |
Output is correct |
5 |
Correct |
153 ms |
8364 KB |
Output is correct |
6 |
Correct |
137 ms |
8132 KB |
Output is correct |
7 |
Correct |
169 ms |
8464 KB |
Output is correct |
8 |
Correct |
141 ms |
8092 KB |
Output is correct |
9 |
Correct |
139 ms |
8124 KB |
Output is correct |
10 |
Correct |
155 ms |
8120 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
2 ms |
340 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
11 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
2 ms |
340 KB |
Output is correct |
10 |
Correct |
40 ms |
5148 KB |
Output is correct |
11 |
Correct |
41 ms |
6208 KB |
Output is correct |
12 |
Correct |
42 ms |
6224 KB |
Output is correct |
13 |
Correct |
43 ms |
6464 KB |
Output is correct |
14 |
Correct |
45 ms |
6456 KB |
Output is correct |
15 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
16 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
2 ms |
340 KB |
Output is correct |
9 |
Correct |
40 ms |
5148 KB |
Output is correct |
10 |
Correct |
41 ms |
6208 KB |
Output is correct |
11 |
Correct |
42 ms |
6224 KB |
Output is correct |
12 |
Correct |
43 ms |
6464 KB |
Output is correct |
13 |
Correct |
45 ms |
6456 KB |
Output is correct |
14 |
Correct |
41 ms |
5260 KB |
Output is correct |
15 |
Correct |
134 ms |
7844 KB |
Output is correct |
16 |
Correct |
119 ms |
7692 KB |
Output is correct |
17 |
Correct |
126 ms |
8020 KB |
Output is correct |
18 |
Correct |
135 ms |
8020 KB |
Output is correct |
19 |
Correct |
143 ms |
8028 KB |
Output is correct |
20 |
Correct |
154 ms |
8196 KB |
Output is correct |
21 |
Correct |
153 ms |
8364 KB |
Output is correct |
22 |
Correct |
137 ms |
8132 KB |
Output is correct |
23 |
Correct |
169 ms |
8464 KB |
Output is correct |
24 |
Correct |
141 ms |
8092 KB |
Output is correct |
25 |
Correct |
139 ms |
8124 KB |
Output is correct |
26 |
Correct |
155 ms |
8120 KB |
Output is correct |
27 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
28 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
2 ms |
340 KB |
Output is correct |
10 |
Correct |
40 ms |
5148 KB |
Output is correct |
11 |
Correct |
41 ms |
6208 KB |
Output is correct |
12 |
Correct |
42 ms |
6224 KB |
Output is correct |
13 |
Correct |
43 ms |
6464 KB |
Output is correct |
14 |
Correct |
45 ms |
6456 KB |
Output is correct |
15 |
Correct |
41 ms |
5260 KB |
Output is correct |
16 |
Correct |
134 ms |
7844 KB |
Output is correct |
17 |
Correct |
119 ms |
7692 KB |
Output is correct |
18 |
Correct |
126 ms |
8020 KB |
Output is correct |
19 |
Correct |
135 ms |
8020 KB |
Output is correct |
20 |
Correct |
143 ms |
8028 KB |
Output is correct |
21 |
Correct |
154 ms |
8196 KB |
Output is correct |
22 |
Correct |
153 ms |
8364 KB |
Output is correct |
23 |
Correct |
137 ms |
8132 KB |
Output is correct |
24 |
Correct |
169 ms |
8464 KB |
Output is correct |
25 |
Correct |
141 ms |
8092 KB |
Output is correct |
26 |
Correct |
139 ms |
8124 KB |
Output is correct |
27 |
Correct |
155 ms |
8120 KB |
Output is correct |
28 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
29 |
Halted |
0 ms |
0 KB |
- |