#include "swap.h"
#include <bits/stdc++.h>
using namespace std;
#define all(a) begin(a),end(a)
#define sz(a) (int)a.size()
#define pb push_back
const int mxN = (int)3e5+10;
int n, m, deg[mxN];
int p[mxN], cycle[mxN], line[mxN];
vector<array<int,3>> edges;
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.pb({W[i],U[i],V[i]});
sort(all(edges),[&](array<int,3> a, array<int,3> b){
return a[0]<b[0];
});
}
int findSet(int i){return p[i]==i?i:p[i]=findSet(p[i]);}
bool isSameSet(int i, int j) { return findSet(i)==findSet(j); }
void unionSet(int i, int j){
deg[i]++, deg[j]++;
int x = findSet(i), y = findSet(j);
if(x==y){
cycle[x] = true;
return;
}
if(!line[x] or !line[y] or deg[i]>=3 or deg[j]>=3)
line[x]=line[y]=0;
p[y] = x;
}
bool check(int x, int s, int t){
for(int i = 0; i < n; i++)
p[i]=i,cycle[i]=0,deg[i]=0,line[i]=1;
for(int i = 0; i <= x; i++)
unionSet(edges[i][1],edges[i][2]);
if(!isSameSet(s,t)) return false;
int set = findSet(s);
return cycle[set] or !line[set];
}
int getMinimumFuelCapacity(int X, int Y) {
int l = 0, r = m-1;
if(!check(r,X,Y)) return -1;
while(l<r){
int mid = (l+r)/2;
if(check(mid,X,Y)) r=mid;
else l=mid+1;
}
return edges[l][0];
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4444 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
3 |
Correct |
0 ms |
4444 KB |
Output is correct |
4 |
Correct |
1 ms |
4444 KB |
Output is correct |
5 |
Correct |
1 ms |
4444 KB |
Output is correct |
6 |
Correct |
1 ms |
4444 KB |
Output is correct |
7 |
Correct |
1 ms |
4556 KB |
Output is correct |
8 |
Correct |
1 ms |
4444 KB |
Output is correct |
9 |
Correct |
25 ms |
8236 KB |
Output is correct |
10 |
Correct |
33 ms |
9056 KB |
Output is correct |
11 |
Correct |
35 ms |
8920 KB |
Output is correct |
12 |
Correct |
38 ms |
9140 KB |
Output is correct |
13 |
Correct |
36 ms |
9520 KB |
Output is correct |
14 |
Execution timed out |
2074 ms |
8492 KB |
Time limit exceeded |
15 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4444 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
3 |
Execution timed out |
2049 ms |
12788 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4444 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
3 |
Correct |
0 ms |
4444 KB |
Output is correct |
4 |
Correct |
1 ms |
4444 KB |
Output is correct |
5 |
Correct |
1 ms |
4444 KB |
Output is correct |
6 |
Correct |
1 ms |
4444 KB |
Output is correct |
7 |
Correct |
1 ms |
4556 KB |
Output is correct |
8 |
Correct |
1 ms |
4444 KB |
Output is correct |
9 |
Correct |
1 ms |
4440 KB |
Output is correct |
10 |
Correct |
1 ms |
4444 KB |
Output is correct |
11 |
Correct |
1 ms |
4444 KB |
Output is correct |
12 |
Correct |
1 ms |
4444 KB |
Output is correct |
13 |
Correct |
1 ms |
4444 KB |
Output is correct |
14 |
Correct |
1 ms |
4444 KB |
Output is correct |
15 |
Correct |
1 ms |
4444 KB |
Output is correct |
16 |
Correct |
1 ms |
4444 KB |
Output is correct |
17 |
Correct |
1 ms |
4444 KB |
Output is correct |
18 |
Correct |
1 ms |
4444 KB |
Output is correct |
19 |
Correct |
1 ms |
4548 KB |
Output is correct |
20 |
Correct |
1 ms |
4444 KB |
Output is correct |
21 |
Correct |
2 ms |
4444 KB |
Output is correct |
22 |
Correct |
2 ms |
4444 KB |
Output is correct |
23 |
Correct |
1 ms |
4444 KB |
Output is correct |
24 |
Correct |
2 ms |
4444 KB |
Output is correct |
25 |
Correct |
2 ms |
4444 KB |
Output is correct |
26 |
Correct |
2 ms |
4592 KB |
Output is correct |
27 |
Correct |
2 ms |
4444 KB |
Output is correct |
28 |
Correct |
2 ms |
4444 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4440 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
3 |
Correct |
1 ms |
4444 KB |
Output is correct |
4 |
Correct |
0 ms |
4444 KB |
Output is correct |
5 |
Correct |
1 ms |
4444 KB |
Output is correct |
6 |
Correct |
1 ms |
4444 KB |
Output is correct |
7 |
Correct |
1 ms |
4444 KB |
Output is correct |
8 |
Correct |
1 ms |
4556 KB |
Output is correct |
9 |
Correct |
1 ms |
4444 KB |
Output is correct |
10 |
Correct |
25 ms |
8236 KB |
Output is correct |
11 |
Correct |
33 ms |
9056 KB |
Output is correct |
12 |
Correct |
35 ms |
8920 KB |
Output is correct |
13 |
Correct |
38 ms |
9140 KB |
Output is correct |
14 |
Correct |
36 ms |
9520 KB |
Output is correct |
15 |
Correct |
1 ms |
4444 KB |
Output is correct |
16 |
Correct |
1 ms |
4444 KB |
Output is correct |
17 |
Correct |
1 ms |
4444 KB |
Output is correct |
18 |
Correct |
1 ms |
4444 KB |
Output is correct |
19 |
Correct |
1 ms |
4444 KB |
Output is correct |
20 |
Correct |
1 ms |
4444 KB |
Output is correct |
21 |
Correct |
1 ms |
4444 KB |
Output is correct |
22 |
Correct |
1 ms |
4444 KB |
Output is correct |
23 |
Correct |
1 ms |
4444 KB |
Output is correct |
24 |
Correct |
1 ms |
4548 KB |
Output is correct |
25 |
Correct |
1 ms |
4444 KB |
Output is correct |
26 |
Correct |
2 ms |
4444 KB |
Output is correct |
27 |
Correct |
2 ms |
4444 KB |
Output is correct |
28 |
Correct |
1 ms |
4444 KB |
Output is correct |
29 |
Correct |
2 ms |
4444 KB |
Output is correct |
30 |
Correct |
2 ms |
4444 KB |
Output is correct |
31 |
Correct |
2 ms |
4592 KB |
Output is correct |
32 |
Correct |
2 ms |
4444 KB |
Output is correct |
33 |
Correct |
2 ms |
4444 KB |
Output is correct |
34 |
Correct |
7 ms |
5404 KB |
Output is correct |
35 |
Correct |
161 ms |
8996 KB |
Output is correct |
36 |
Correct |
168 ms |
9004 KB |
Output is correct |
37 |
Correct |
200 ms |
9016 KB |
Output is correct |
38 |
Correct |
174 ms |
8764 KB |
Output is correct |
39 |
Correct |
226 ms |
8944 KB |
Output is correct |
40 |
Correct |
191 ms |
8360 KB |
Output is correct |
41 |
Correct |
169 ms |
9264 KB |
Output is correct |
42 |
Correct |
164 ms |
9016 KB |
Output is correct |
43 |
Correct |
127 ms |
9264 KB |
Output is correct |
44 |
Correct |
270 ms |
9268 KB |
Output is correct |
45 |
Correct |
269 ms |
12292 KB |
Output is correct |
46 |
Correct |
172 ms |
9004 KB |
Output is correct |
47 |
Correct |
183 ms |
9008 KB |
Output is correct |
48 |
Correct |
251 ms |
9240 KB |
Output is correct |
49 |
Correct |
50 ms |
11136 KB |
Output is correct |
50 |
Correct |
52 ms |
9848 KB |
Output is correct |
51 |
Correct |
176 ms |
10372 KB |
Output is correct |
52 |
Correct |
214 ms |
12124 KB |
Output is correct |
53 |
Correct |
198 ms |
12712 KB |
Output is correct |
54 |
Correct |
211 ms |
13856 KB |
Output is correct |
55 |
Correct |
173 ms |
9128 KB |
Output is correct |
56 |
Correct |
405 ms |
12516 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4444 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
3 |
Correct |
0 ms |
4444 KB |
Output is correct |
4 |
Correct |
1 ms |
4444 KB |
Output is correct |
5 |
Correct |
1 ms |
4444 KB |
Output is correct |
6 |
Correct |
1 ms |
4444 KB |
Output is correct |
7 |
Correct |
1 ms |
4556 KB |
Output is correct |
8 |
Correct |
1 ms |
4444 KB |
Output is correct |
9 |
Correct |
25 ms |
8236 KB |
Output is correct |
10 |
Correct |
33 ms |
9056 KB |
Output is correct |
11 |
Correct |
35 ms |
8920 KB |
Output is correct |
12 |
Correct |
38 ms |
9140 KB |
Output is correct |
13 |
Correct |
36 ms |
9520 KB |
Output is correct |
14 |
Execution timed out |
2074 ms |
8492 KB |
Time limit exceeded |
15 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4440 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
3 |
Correct |
1 ms |
4444 KB |
Output is correct |
4 |
Correct |
0 ms |
4444 KB |
Output is correct |
5 |
Correct |
1 ms |
4444 KB |
Output is correct |
6 |
Correct |
1 ms |
4444 KB |
Output is correct |
7 |
Correct |
1 ms |
4444 KB |
Output is correct |
8 |
Correct |
1 ms |
4556 KB |
Output is correct |
9 |
Correct |
1 ms |
4444 KB |
Output is correct |
10 |
Correct |
25 ms |
8236 KB |
Output is correct |
11 |
Correct |
33 ms |
9056 KB |
Output is correct |
12 |
Correct |
35 ms |
8920 KB |
Output is correct |
13 |
Correct |
38 ms |
9140 KB |
Output is correct |
14 |
Correct |
36 ms |
9520 KB |
Output is correct |
15 |
Execution timed out |
2074 ms |
8492 KB |
Time limit exceeded |
16 |
Halted |
0 ms |
0 KB |
- |