#include<bits/stdc++.h>
using namespace std;
struct dsu {
vector<int> p;
int n;
dsu(int n) {
resize(n);
}
dsu() {
}
void resize(int _n) {
n = _n;
p = vector<int> (n, -1);
}
int get(int x) {
return p[x] < 0 ? x : p[x] = get(p[x]);
}
bool unite(int x, int y) {
x = get(x); y = get(y);
if (x != y) {
if (p[x] < p[y]) swap(x, y);
p[y] += p[x];
p[x] = y;
return true;
}
return false;
}
} d;
const int N = 1e5 + 3;
int n, m;
vector<tuple<int,int,int>> edges;
int deg[N];
vector<int> event[N];
bool can[N];
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.emplace_back(w[i], u[i], v[i]);
sort(edges.begin(), edges.end());
/*d.resize(n);
for (auto&x : edges) {
deg[get<1>(x)]++;
deg[get<2>(x)]++;
int u = d.get(get<1>(x)), v = d.get(get<2>(x));
if (u == v) {
if (!can[u]) {
event[u].emplace_back(get<0>(x));
can[u] = true;
}
}
else {
d.unite(u, v);
if (u != d.get(u)) swap(u, v);
}
}*/
}
int getMinimumFuelCapacity(int X, int Y) {
d.resize(n);
for (int i = 0; i < n; i++) deg[i] = 0, can[i] = false;
for (auto&x : edges) {
++deg[get<1>(x)];
++deg[get<2>(x)];
int u = d.get(get<1>(x)), v = d.get(get<2>(x));
if (u == v) {
can[u] = true;
}
else {
d.unite(u, v);
if (u != d.get(u)) swap(u, v);
can[u] |= can[v];
if (deg[get<1>(x)] >= 3 || deg[get<2>(x)] >= 3) {
can[u] = true;
}
}
if (d.get(X) == d.get(Y) && can[d.get(X)]) return get<0>(x);
}
return -1;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
2636 KB |
Output is correct |
2 |
Correct |
2 ms |
2636 KB |
Output is correct |
3 |
Correct |
2 ms |
2636 KB |
Output is correct |
4 |
Correct |
3 ms |
2636 KB |
Output is correct |
5 |
Correct |
3 ms |
2636 KB |
Output is correct |
6 |
Correct |
3 ms |
2636 KB |
Output is correct |
7 |
Correct |
3 ms |
2636 KB |
Output is correct |
8 |
Correct |
3 ms |
2584 KB |
Output is correct |
9 |
Correct |
54 ms |
6128 KB |
Output is correct |
10 |
Correct |
61 ms |
6460 KB |
Output is correct |
11 |
Correct |
78 ms |
6452 KB |
Output is correct |
12 |
Correct |
78 ms |
6636 KB |
Output is correct |
13 |
Correct |
61 ms |
6640 KB |
Output is correct |
14 |
Execution timed out |
2070 ms |
6256 KB |
Time limit exceeded |
15 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
2636 KB |
Output is correct |
2 |
Correct |
2 ms |
2636 KB |
Output is correct |
3 |
Execution timed out |
2085 ms |
8272 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
2636 KB |
Output is correct |
2 |
Correct |
2 ms |
2636 KB |
Output is correct |
3 |
Correct |
2 ms |
2636 KB |
Output is correct |
4 |
Correct |
3 ms |
2636 KB |
Output is correct |
5 |
Correct |
3 ms |
2636 KB |
Output is correct |
6 |
Correct |
3 ms |
2636 KB |
Output is correct |
7 |
Correct |
3 ms |
2636 KB |
Output is correct |
8 |
Correct |
3 ms |
2584 KB |
Output is correct |
9 |
Correct |
3 ms |
2636 KB |
Output is correct |
10 |
Correct |
3 ms |
2636 KB |
Output is correct |
11 |
Correct |
3 ms |
2636 KB |
Output is correct |
12 |
Correct |
3 ms |
2636 KB |
Output is correct |
13 |
Correct |
3 ms |
2660 KB |
Output is correct |
14 |
Correct |
3 ms |
2636 KB |
Output is correct |
15 |
Correct |
3 ms |
2636 KB |
Output is correct |
16 |
Correct |
3 ms |
2692 KB |
Output is correct |
17 |
Correct |
3 ms |
2636 KB |
Output is correct |
18 |
Correct |
3 ms |
2664 KB |
Output is correct |
19 |
Correct |
3 ms |
2672 KB |
Output is correct |
20 |
Correct |
3 ms |
2668 KB |
Output is correct |
21 |
Correct |
3 ms |
2636 KB |
Output is correct |
22 |
Correct |
3 ms |
2672 KB |
Output is correct |
23 |
Correct |
3 ms |
2636 KB |
Output is correct |
24 |
Correct |
3 ms |
2764 KB |
Output is correct |
25 |
Correct |
3 ms |
2764 KB |
Output is correct |
26 |
Correct |
3 ms |
2708 KB |
Output is correct |
27 |
Correct |
3 ms |
2636 KB |
Output is correct |
28 |
Correct |
3 ms |
2672 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
2636 KB |
Output is correct |
2 |
Correct |
2 ms |
2636 KB |
Output is correct |
3 |
Correct |
2 ms |
2636 KB |
Output is correct |
4 |
Correct |
2 ms |
2636 KB |
Output is correct |
5 |
Correct |
3 ms |
2636 KB |
Output is correct |
6 |
Correct |
3 ms |
2636 KB |
Output is correct |
7 |
Correct |
3 ms |
2636 KB |
Output is correct |
8 |
Correct |
3 ms |
2636 KB |
Output is correct |
9 |
Correct |
3 ms |
2584 KB |
Output is correct |
10 |
Correct |
54 ms |
6128 KB |
Output is correct |
11 |
Correct |
61 ms |
6460 KB |
Output is correct |
12 |
Correct |
78 ms |
6452 KB |
Output is correct |
13 |
Correct |
78 ms |
6636 KB |
Output is correct |
14 |
Correct |
61 ms |
6640 KB |
Output is correct |
15 |
Correct |
3 ms |
2636 KB |
Output is correct |
16 |
Correct |
3 ms |
2636 KB |
Output is correct |
17 |
Correct |
3 ms |
2636 KB |
Output is correct |
18 |
Correct |
3 ms |
2660 KB |
Output is correct |
19 |
Correct |
3 ms |
2636 KB |
Output is correct |
20 |
Correct |
3 ms |
2636 KB |
Output is correct |
21 |
Correct |
3 ms |
2692 KB |
Output is correct |
22 |
Correct |
3 ms |
2636 KB |
Output is correct |
23 |
Correct |
3 ms |
2664 KB |
Output is correct |
24 |
Correct |
3 ms |
2672 KB |
Output is correct |
25 |
Correct |
3 ms |
2668 KB |
Output is correct |
26 |
Correct |
3 ms |
2636 KB |
Output is correct |
27 |
Correct |
3 ms |
2672 KB |
Output is correct |
28 |
Correct |
3 ms |
2636 KB |
Output is correct |
29 |
Correct |
3 ms |
2764 KB |
Output is correct |
30 |
Correct |
3 ms |
2764 KB |
Output is correct |
31 |
Correct |
3 ms |
2708 KB |
Output is correct |
32 |
Correct |
3 ms |
2636 KB |
Output is correct |
33 |
Correct |
3 ms |
2672 KB |
Output is correct |
34 |
Correct |
9 ms |
3532 KB |
Output is correct |
35 |
Correct |
70 ms |
8408 KB |
Output is correct |
36 |
Correct |
66 ms |
8468 KB |
Output is correct |
37 |
Correct |
66 ms |
8400 KB |
Output is correct |
38 |
Correct |
64 ms |
8412 KB |
Output is correct |
39 |
Correct |
64 ms |
8388 KB |
Output is correct |
40 |
Correct |
75 ms |
7996 KB |
Output is correct |
41 |
Correct |
74 ms |
8744 KB |
Output is correct |
42 |
Correct |
74 ms |
8460 KB |
Output is correct |
43 |
Correct |
57 ms |
8420 KB |
Output is correct |
44 |
Correct |
70 ms |
8764 KB |
Output is correct |
45 |
Correct |
89 ms |
12412 KB |
Output is correct |
46 |
Correct |
68 ms |
8460 KB |
Output is correct |
47 |
Correct |
66 ms |
8508 KB |
Output is correct |
48 |
Correct |
68 ms |
8944 KB |
Output is correct |
49 |
Correct |
79 ms |
12244 KB |
Output is correct |
50 |
Correct |
54 ms |
9420 KB |
Output is correct |
51 |
Correct |
77 ms |
10032 KB |
Output is correct |
52 |
Correct |
102 ms |
13088 KB |
Output is correct |
53 |
Correct |
101 ms |
13752 KB |
Output is correct |
54 |
Correct |
118 ms |
14444 KB |
Output is correct |
55 |
Correct |
57 ms |
8420 KB |
Output is correct |
56 |
Correct |
114 ms |
13496 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
2636 KB |
Output is correct |
2 |
Correct |
2 ms |
2636 KB |
Output is correct |
3 |
Correct |
2 ms |
2636 KB |
Output is correct |
4 |
Correct |
3 ms |
2636 KB |
Output is correct |
5 |
Correct |
3 ms |
2636 KB |
Output is correct |
6 |
Correct |
3 ms |
2636 KB |
Output is correct |
7 |
Correct |
3 ms |
2636 KB |
Output is correct |
8 |
Correct |
3 ms |
2584 KB |
Output is correct |
9 |
Correct |
54 ms |
6128 KB |
Output is correct |
10 |
Correct |
61 ms |
6460 KB |
Output is correct |
11 |
Correct |
78 ms |
6452 KB |
Output is correct |
12 |
Correct |
78 ms |
6636 KB |
Output is correct |
13 |
Correct |
61 ms |
6640 KB |
Output is correct |
14 |
Execution timed out |
2070 ms |
6256 KB |
Time limit exceeded |
15 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
2636 KB |
Output is correct |
2 |
Correct |
2 ms |
2636 KB |
Output is correct |
3 |
Correct |
2 ms |
2636 KB |
Output is correct |
4 |
Correct |
2 ms |
2636 KB |
Output is correct |
5 |
Correct |
3 ms |
2636 KB |
Output is correct |
6 |
Correct |
3 ms |
2636 KB |
Output is correct |
7 |
Correct |
3 ms |
2636 KB |
Output is correct |
8 |
Correct |
3 ms |
2636 KB |
Output is correct |
9 |
Correct |
3 ms |
2584 KB |
Output is correct |
10 |
Correct |
54 ms |
6128 KB |
Output is correct |
11 |
Correct |
61 ms |
6460 KB |
Output is correct |
12 |
Correct |
78 ms |
6452 KB |
Output is correct |
13 |
Correct |
78 ms |
6636 KB |
Output is correct |
14 |
Correct |
61 ms |
6640 KB |
Output is correct |
15 |
Execution timed out |
2070 ms |
6256 KB |
Time limit exceeded |
16 |
Halted |
0 ms |
0 KB |
- |