#include "swap.h"
#include <bits/stdc++.h>
using namespace std;
mt19937 rng(0);
const int INF = (int) 1e9 + 7;
int n;
int m;
vector<int> t;
vector<int> dim;
vector<int> is_line;
vector<int> is_endpoint;
int root(int a) {
if (t[a] == a) {
return t[a];
} else {
return t[a] = root(t[a]);
}
}
void join(int a, int b, int val) {
int x = a, y = b;
a = root(a);
b = root(b);
if (a == b) {
is_line[a] = 0;
return;
}
//if (rng() & 1) {
// swap(a, b);
// }
if (is_line[a] && is_line[b] && is_endpoint[x] && is_endpoint[y]) {
is_line[a] = 1;
if (dim[a] > 1) {
is_endpoint[x] = 0;
}
if (dim[b] > 1) {
is_endpoint[y] = 0;
}
} else {
is_line[a] = 0;
}
dim[a] += dim[b];
t[b] = a;
}
void clr() {
t.resize(n);
is_line.resize(n);
is_endpoint.resize(n);
dim.resize(n);
for (int i = 0; i < n; i++) {
t[i] = i;
is_line[i] = 1;
is_endpoint[i] = 1;
dim[i] = 1;
}
}
struct Edge {
int a;
int b;
int w;
};
bool operator < (Edge first, Edge second) {
return first.w < second.w;
}
vector<Edge> edges;
void init(int N, int M, vector<int> U, vector<int> V, vector<int> W) {
n = N;
m = M;
assert((int) U.size() == m);
assert((int) V.size() == m);
assert((int) W.size() == m);
edges.clear();
for (int i = 0; i < m; i++) {
edges.push_back({U[i], V[i], W[i]});
}
sort(edges.begin(), edges.end());
}
int getMinimumFuelCapacity(int x, int y) {
clr();
for (auto &edge : edges) {
int a = edge.a;
int b = edge.b;
int w = edge.w;
join(a, b, w);
//cout << a << " " << b << " | " << w << " and I care about " << x << " " << y << "\n";
if (root(x) == root(y) && !is_line[root(x)]) {
return w;
}
}
return -1;
}
# |
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 |
1 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 |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
37 ms |
3792 KB |
Output is correct |
10 |
Correct |
57 ms |
4164 KB |
Output is correct |
11 |
Correct |
72 ms |
4164 KB |
Output is correct |
12 |
Correct |
71 ms |
4288 KB |
Output is correct |
13 |
Correct |
56 ms |
4516 KB |
Output is correct |
14 |
Execution timed out |
2045 ms |
3912 KB |
Time limit exceeded |
15 |
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 |
Execution timed out |
2065 ms |
6184 KB |
Time limit exceeded |
4 |
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 |
1 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 |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
1 ms |
340 KB |
Output is correct |
22 |
Correct |
1 ms |
340 KB |
Output is correct |
23 |
Correct |
1 ms |
340 KB |
Output is correct |
24 |
Correct |
2 ms |
348 KB |
Output is correct |
25 |
Correct |
2 ms |
316 KB |
Output is correct |
26 |
Correct |
2 ms |
320 KB |
Output is correct |
27 |
Correct |
1 ms |
340 KB |
Output is correct |
28 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
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 |
1 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 |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
37 ms |
3792 KB |
Output is correct |
11 |
Correct |
57 ms |
4164 KB |
Output is correct |
12 |
Correct |
72 ms |
4164 KB |
Output is correct |
13 |
Correct |
71 ms |
4288 KB |
Output is correct |
14 |
Correct |
56 ms |
4516 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
1 ms |
340 KB |
Output is correct |
22 |
Correct |
1 ms |
340 KB |
Output is correct |
23 |
Correct |
1 ms |
340 KB |
Output is correct |
24 |
Correct |
1 ms |
340 KB |
Output is correct |
25 |
Correct |
1 ms |
340 KB |
Output is correct |
26 |
Correct |
1 ms |
340 KB |
Output is correct |
27 |
Correct |
1 ms |
340 KB |
Output is correct |
28 |
Correct |
1 ms |
340 KB |
Output is correct |
29 |
Correct |
2 ms |
348 KB |
Output is correct |
30 |
Correct |
2 ms |
316 KB |
Output is correct |
31 |
Correct |
2 ms |
320 KB |
Output is correct |
32 |
Correct |
1 ms |
340 KB |
Output is correct |
33 |
Correct |
1 ms |
340 KB |
Output is correct |
34 |
Correct |
6 ms |
1156 KB |
Output is correct |
35 |
Correct |
60 ms |
6064 KB |
Output is correct |
36 |
Correct |
62 ms |
6052 KB |
Output is correct |
37 |
Correct |
59 ms |
6060 KB |
Output is correct |
38 |
Correct |
58 ms |
6056 KB |
Output is correct |
39 |
Correct |
59 ms |
6036 KB |
Output is correct |
40 |
Correct |
55 ms |
5684 KB |
Output is correct |
41 |
Correct |
63 ms |
6332 KB |
Output is correct |
42 |
Correct |
62 ms |
6060 KB |
Output is correct |
43 |
Correct |
48 ms |
6072 KB |
Output is correct |
44 |
Correct |
65 ms |
6324 KB |
Output is correct |
45 |
Correct |
83 ms |
9952 KB |
Output is correct |
46 |
Correct |
62 ms |
6152 KB |
Output is correct |
47 |
Correct |
61 ms |
6056 KB |
Output is correct |
48 |
Correct |
65 ms |
6604 KB |
Output is correct |
49 |
Correct |
59 ms |
9920 KB |
Output is correct |
50 |
Correct |
50 ms |
7064 KB |
Output is correct |
51 |
Correct |
69 ms |
7676 KB |
Output is correct |
52 |
Correct |
102 ms |
10612 KB |
Output is correct |
53 |
Correct |
91 ms |
11412 KB |
Output is correct |
54 |
Correct |
103 ms |
12092 KB |
Output is correct |
55 |
Correct |
54 ms |
6048 KB |
Output is correct |
56 |
Correct |
108 ms |
11072 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 |
1 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 |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
37 ms |
3792 KB |
Output is correct |
10 |
Correct |
57 ms |
4164 KB |
Output is correct |
11 |
Correct |
72 ms |
4164 KB |
Output is correct |
12 |
Correct |
71 ms |
4288 KB |
Output is correct |
13 |
Correct |
56 ms |
4516 KB |
Output is correct |
14 |
Execution timed out |
2045 ms |
3912 KB |
Time limit exceeded |
15 |
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 |
1 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 |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
37 ms |
3792 KB |
Output is correct |
11 |
Correct |
57 ms |
4164 KB |
Output is correct |
12 |
Correct |
72 ms |
4164 KB |
Output is correct |
13 |
Correct |
71 ms |
4288 KB |
Output is correct |
14 |
Correct |
56 ms |
4516 KB |
Output is correct |
15 |
Execution timed out |
2045 ms |
3912 KB |
Time limit exceeded |
16 |
Halted |
0 ms |
0 KB |
- |