#include <bits/stdc++.h>
// #include "grader_swap.cpp"
using namespace std;
#define lli long long int
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define test(x) cout << "Line(" << __LINE__ << ") " #x << ' ' << x << endl
#define printv(x) {\
for (auto i : x) cout << i << ' ';\
cout << endl;\
}
#define pii pair <int, int>
#define pll pair <lli, lli>
#define X first
#define Y second
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
template<typename A, typename B>
ostream& operator << (ostream& o, pair<A, B> a){
return o << a.X << ' ' << a.Y;
}
template<typename A, typename B>
istream& operator >> (istream& o, pair<A, B> &a){
return o >> a.X >> a.Y;
}
const int mod = 1e9 + 7, abc = 864197532, Doludu = 123, N = 100001, logN = 18, K = 40;
int n, m;
vector <int> dsu, tag, deg, mx;
void init() {
dsu.assign(n, 0);
deg.assign(n, 0);
tag.assign(n, false);
mx.assign(n, 0);
iota(all(dsu), 0);
}
int Find(int v) {
if (dsu[v] == v) return v;
return dsu[v] = Find(dsu[v]);
}
bool Union(int u, int v) {
int nu = Find(u), nv = Find(v);
if (nu == nv) {
tag[nu] = true;
return false;
}
deg[u]++, deg[v]++;
mx[nu] = max(mx[nu], deg[u]);
mx[nv] = max(mx[nv], deg[v]);
dsu[nu] = nv;
mx[nv] = max(mx[nv], mx[nu]);
if (tag[nu]) tag[nv] = true;
return true;
}
vector <int> u, v, w, p;
void init(int _n, int _m, vector <int> _u, vector <int> _v, vector <int> _w) {
n = _n, m = _m, u = _u, v = _v, w = _w;
p.resize(m);
iota(all(p), 0);
sort(all(p), [&](int i, int j) {
return w[i] < w[j];
});
}
int getMinimumFuelCapacity(int U, int V) {
vector <int> cnt(n, 0);
init();
for (int i : p) {
Union(u[i], v[i]);
if (Find(U) == Find(V) && (tag[Find(U)] || mx[Find(V)] > 2)) {
return w[i];
}
}
return -1;
}
/*
5 6
0 1 4
0 2 4
1 2 1
1 3 2
2 3 3
1 4 10
3
1 2
2 4
0 1
3 2
0 1 5
0 2 5
1
1 2
*/
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
336 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
48 ms |
3880 KB |
Output is correct |
10 |
Correct |
74 ms |
4700 KB |
Output is correct |
11 |
Correct |
96 ms |
4652 KB |
Output is correct |
12 |
Correct |
83 ms |
4908 KB |
Output is correct |
13 |
Correct |
80 ms |
5288 KB |
Output is correct |
14 |
Execution timed out |
2073 ms |
4124 KB |
Time limit exceeded |
15 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Execution timed out |
2097 ms |
6976 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
336 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
204 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
1 ms |
332 KB |
Output is correct |
13 |
Correct |
1 ms |
320 KB |
Output is correct |
14 |
Correct |
1 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
332 KB |
Output is correct |
16 |
Correct |
2 ms |
332 KB |
Output is correct |
17 |
Correct |
1 ms |
364 KB |
Output is correct |
18 |
Correct |
2 ms |
332 KB |
Output is correct |
19 |
Correct |
2 ms |
332 KB |
Output is correct |
20 |
Correct |
1 ms |
332 KB |
Output is correct |
21 |
Correct |
1 ms |
332 KB |
Output is correct |
22 |
Correct |
1 ms |
332 KB |
Output is correct |
23 |
Correct |
1 ms |
204 KB |
Output is correct |
24 |
Correct |
2 ms |
332 KB |
Output is correct |
25 |
Correct |
2 ms |
332 KB |
Output is correct |
26 |
Correct |
2 ms |
332 KB |
Output is correct |
27 |
Correct |
1 ms |
332 KB |
Output is correct |
28 |
Correct |
2 ms |
332 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
336 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
48 ms |
3880 KB |
Output is correct |
11 |
Correct |
74 ms |
4700 KB |
Output is correct |
12 |
Correct |
96 ms |
4652 KB |
Output is correct |
13 |
Correct |
83 ms |
4908 KB |
Output is correct |
14 |
Correct |
80 ms |
5288 KB |
Output is correct |
15 |
Correct |
1 ms |
332 KB |
Output is correct |
16 |
Correct |
1 ms |
332 KB |
Output is correct |
17 |
Correct |
1 ms |
332 KB |
Output is correct |
18 |
Correct |
1 ms |
320 KB |
Output is correct |
19 |
Correct |
1 ms |
332 KB |
Output is correct |
20 |
Correct |
1 ms |
332 KB |
Output is correct |
21 |
Correct |
2 ms |
332 KB |
Output is correct |
22 |
Correct |
1 ms |
364 KB |
Output is correct |
23 |
Correct |
2 ms |
332 KB |
Output is correct |
24 |
Correct |
2 ms |
332 KB |
Output is correct |
25 |
Correct |
1 ms |
332 KB |
Output is correct |
26 |
Correct |
1 ms |
332 KB |
Output is correct |
27 |
Correct |
1 ms |
332 KB |
Output is correct |
28 |
Correct |
1 ms |
204 KB |
Output is correct |
29 |
Correct |
2 ms |
332 KB |
Output is correct |
30 |
Correct |
2 ms |
332 KB |
Output is correct |
31 |
Correct |
2 ms |
332 KB |
Output is correct |
32 |
Correct |
1 ms |
332 KB |
Output is correct |
33 |
Correct |
2 ms |
332 KB |
Output is correct |
34 |
Correct |
9 ms |
972 KB |
Output is correct |
35 |
Correct |
87 ms |
5152 KB |
Output is correct |
36 |
Correct |
82 ms |
4940 KB |
Output is correct |
37 |
Correct |
83 ms |
4908 KB |
Output is correct |
38 |
Correct |
94 ms |
4912 KB |
Output is correct |
39 |
Correct |
83 ms |
4932 KB |
Output is correct |
40 |
Correct |
79 ms |
4524 KB |
Output is correct |
41 |
Correct |
86 ms |
4908 KB |
Output is correct |
42 |
Correct |
81 ms |
4936 KB |
Output is correct |
43 |
Correct |
64 ms |
4932 KB |
Output is correct |
44 |
Correct |
91 ms |
4948 KB |
Output is correct |
45 |
Correct |
110 ms |
6004 KB |
Output is correct |
46 |
Correct |
81 ms |
5024 KB |
Output is correct |
47 |
Correct |
82 ms |
4944 KB |
Output is correct |
48 |
Correct |
90 ms |
5236 KB |
Output is correct |
49 |
Correct |
70 ms |
6536 KB |
Output is correct |
50 |
Correct |
57 ms |
5060 KB |
Output is correct |
51 |
Correct |
87 ms |
5268 KB |
Output is correct |
52 |
Correct |
115 ms |
6692 KB |
Output is correct |
53 |
Correct |
139 ms |
7532 KB |
Output is correct |
54 |
Correct |
136 ms |
8188 KB |
Output is correct |
55 |
Correct |
72 ms |
6796 KB |
Output is correct |
56 |
Correct |
144 ms |
10612 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
336 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
48 ms |
3880 KB |
Output is correct |
10 |
Correct |
74 ms |
4700 KB |
Output is correct |
11 |
Correct |
96 ms |
4652 KB |
Output is correct |
12 |
Correct |
83 ms |
4908 KB |
Output is correct |
13 |
Correct |
80 ms |
5288 KB |
Output is correct |
14 |
Execution timed out |
2073 ms |
4124 KB |
Time limit exceeded |
15 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
336 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
48 ms |
3880 KB |
Output is correct |
11 |
Correct |
74 ms |
4700 KB |
Output is correct |
12 |
Correct |
96 ms |
4652 KB |
Output is correct |
13 |
Correct |
83 ms |
4908 KB |
Output is correct |
14 |
Correct |
80 ms |
5288 KB |
Output is correct |
15 |
Execution timed out |
2073 ms |
4124 KB |
Time limit exceeded |
16 |
Halted |
0 ms |
0 KB |
- |