#include "swap.h"
#include <bits/stdc++.h>
using namespace std;
#define fr first
#define sc second
#define mp make_pair
#define pb push_back
#define all(x) x.begin(),x.end()
const int maxn = 2e5+10;
const int B = 500;
int n, m, gr[maxn], ds[maxn], dsz[maxn], mn[maxn];
vector<int> mn0[maxn];
vector<pair<int,pair<int,int>>> edgs;
int find(int u) {
if(ds[u] == u) return u;
return ds[u] = find(ds[u]);
}
void join(int u, int v, int id) {
gr[u]++;
gr[v]++;
int mxgr = max(gr[u],gr[v]);
u = find(u);
v = find(v);
if(u == v || mxgr >= 3 || mn[u] != -1 || mn[v] != -1) {
if(mn0[u].size()) {
for(auto x : mn0[u]) {
mn[x] = id;
}
mn0[u].clear();
}
if(mn0[v].size()) {
for(auto x : mn0[v]) {
mn[x] = id;
}
mn0[v].clear();
}
}
if(u == v) return;
if(dsz[u] < dsz[v]) swap(u,v);
for(auto x : mn0[v]) {
mn0[u].pb(x);
}
dsz[u]+= dsz[v];
ds[v] = u;
}
void init(int N, int M, vector<int> U, std::vector<int> V, std::vector<int> W) {
n = N;
m = M;
for(auto i = 0; i < m; i++) {
edgs.pb(mp(W[i],mp(U[i],V[i])));
}
sort(all(edgs));
}
int getMinimumFuelCapacity(int x, int y) {
for(int i = 0; i < n; i++) {
gr[i] = 0;
mn[i] = -1;
ds[i] = i;
dsz[i] = 1;
mn0[i].clear();
mn0[i].pb(i);
}
for(int i = 0; i < m; i++) {
int u = edgs[i].sc.fr;
int v = edgs[i].sc.sc;
join(u,v,i);
if(find(x) == find(y) && mn[x] != -1 && mn[y] != -1) return edgs[i].fr;
}
return -1;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4948 KB |
Output is correct |
2 |
Correct |
3 ms |
5004 KB |
Output is correct |
3 |
Correct |
3 ms |
5012 KB |
Output is correct |
4 |
Correct |
3 ms |
5008 KB |
Output is correct |
5 |
Correct |
3 ms |
5076 KB |
Output is correct |
6 |
Correct |
4 ms |
5076 KB |
Output is correct |
7 |
Correct |
4 ms |
5076 KB |
Output is correct |
8 |
Correct |
4 ms |
5076 KB |
Output is correct |
9 |
Correct |
67 ms |
15092 KB |
Output is correct |
10 |
Correct |
106 ms |
16560 KB |
Output is correct |
11 |
Correct |
111 ms |
16540 KB |
Output is correct |
12 |
Correct |
116 ms |
17216 KB |
Output is correct |
13 |
Correct |
87 ms |
14632 KB |
Output is correct |
14 |
Execution timed out |
2043 ms |
15148 KB |
Time limit exceeded |
15 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4948 KB |
Output is correct |
2 |
Correct |
3 ms |
5004 KB |
Output is correct |
3 |
Execution timed out |
2049 ms |
15128 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4948 KB |
Output is correct |
2 |
Correct |
3 ms |
5004 KB |
Output is correct |
3 |
Correct |
3 ms |
5012 KB |
Output is correct |
4 |
Correct |
3 ms |
5008 KB |
Output is correct |
5 |
Correct |
3 ms |
5076 KB |
Output is correct |
6 |
Correct |
4 ms |
5076 KB |
Output is correct |
7 |
Correct |
4 ms |
5076 KB |
Output is correct |
8 |
Correct |
4 ms |
5076 KB |
Output is correct |
9 |
Correct |
3 ms |
4948 KB |
Output is correct |
10 |
Correct |
4 ms |
5076 KB |
Output is correct |
11 |
Correct |
4 ms |
5076 KB |
Output is correct |
12 |
Correct |
4 ms |
5076 KB |
Output is correct |
13 |
Correct |
4 ms |
5076 KB |
Output is correct |
14 |
Correct |
4 ms |
5076 KB |
Output is correct |
15 |
Correct |
4 ms |
5076 KB |
Output is correct |
16 |
Correct |
4 ms |
5020 KB |
Output is correct |
17 |
Correct |
3 ms |
5076 KB |
Output is correct |
18 |
Correct |
3 ms |
5076 KB |
Output is correct |
19 |
Correct |
5 ms |
5020 KB |
Output is correct |
20 |
Correct |
4 ms |
5020 KB |
Output is correct |
21 |
Correct |
3 ms |
5016 KB |
Output is correct |
22 |
Correct |
4 ms |
5076 KB |
Output is correct |
23 |
Correct |
4 ms |
5076 KB |
Output is correct |
24 |
Correct |
4 ms |
5076 KB |
Output is correct |
25 |
Correct |
4 ms |
5076 KB |
Output is correct |
26 |
Correct |
4 ms |
5144 KB |
Output is correct |
27 |
Correct |
3 ms |
5016 KB |
Output is correct |
28 |
Correct |
4 ms |
5076 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4948 KB |
Output is correct |
2 |
Correct |
3 ms |
4948 KB |
Output is correct |
3 |
Correct |
3 ms |
5004 KB |
Output is correct |
4 |
Correct |
3 ms |
5012 KB |
Output is correct |
5 |
Correct |
3 ms |
5008 KB |
Output is correct |
6 |
Correct |
3 ms |
5076 KB |
Output is correct |
7 |
Correct |
4 ms |
5076 KB |
Output is correct |
8 |
Correct |
4 ms |
5076 KB |
Output is correct |
9 |
Correct |
4 ms |
5076 KB |
Output is correct |
10 |
Correct |
67 ms |
15092 KB |
Output is correct |
11 |
Correct |
106 ms |
16560 KB |
Output is correct |
12 |
Correct |
111 ms |
16540 KB |
Output is correct |
13 |
Correct |
116 ms |
17216 KB |
Output is correct |
14 |
Correct |
87 ms |
14632 KB |
Output is correct |
15 |
Correct |
4 ms |
5076 KB |
Output is correct |
16 |
Correct |
4 ms |
5076 KB |
Output is correct |
17 |
Correct |
4 ms |
5076 KB |
Output is correct |
18 |
Correct |
4 ms |
5076 KB |
Output is correct |
19 |
Correct |
4 ms |
5076 KB |
Output is correct |
20 |
Correct |
4 ms |
5076 KB |
Output is correct |
21 |
Correct |
4 ms |
5020 KB |
Output is correct |
22 |
Correct |
3 ms |
5076 KB |
Output is correct |
23 |
Correct |
3 ms |
5076 KB |
Output is correct |
24 |
Correct |
5 ms |
5020 KB |
Output is correct |
25 |
Correct |
4 ms |
5020 KB |
Output is correct |
26 |
Correct |
3 ms |
5016 KB |
Output is correct |
27 |
Correct |
4 ms |
5076 KB |
Output is correct |
28 |
Correct |
4 ms |
5076 KB |
Output is correct |
29 |
Correct |
4 ms |
5076 KB |
Output is correct |
30 |
Correct |
4 ms |
5076 KB |
Output is correct |
31 |
Correct |
4 ms |
5144 KB |
Output is correct |
32 |
Correct |
3 ms |
5016 KB |
Output is correct |
33 |
Correct |
4 ms |
5076 KB |
Output is correct |
34 |
Correct |
10 ms |
6292 KB |
Output is correct |
35 |
Correct |
118 ms |
16216 KB |
Output is correct |
36 |
Correct |
117 ms |
16364 KB |
Output is correct |
37 |
Correct |
107 ms |
15580 KB |
Output is correct |
38 |
Correct |
111 ms |
14916 KB |
Output is correct |
39 |
Correct |
98 ms |
14292 KB |
Output is correct |
40 |
Correct |
84 ms |
13256 KB |
Output is correct |
41 |
Correct |
120 ms |
17632 KB |
Output is correct |
42 |
Correct |
118 ms |
17496 KB |
Output is correct |
43 |
Correct |
101 ms |
14040 KB |
Output is correct |
44 |
Correct |
118 ms |
14312 KB |
Output is correct |
45 |
Correct |
106 ms |
15336 KB |
Output is correct |
46 |
Correct |
126 ms |
16300 KB |
Output is correct |
47 |
Correct |
116 ms |
14888 KB |
Output is correct |
48 |
Correct |
110 ms |
14332 KB |
Output is correct |
49 |
Correct |
61 ms |
14656 KB |
Output is correct |
50 |
Correct |
50 ms |
11780 KB |
Output is correct |
51 |
Correct |
78 ms |
13808 KB |
Output is correct |
52 |
Correct |
149 ms |
19564 KB |
Output is correct |
53 |
Correct |
134 ms |
17700 KB |
Output is correct |
54 |
Correct |
164 ms |
21764 KB |
Output is correct |
55 |
Correct |
118 ms |
13924 KB |
Output is correct |
56 |
Correct |
147 ms |
17500 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4948 KB |
Output is correct |
2 |
Correct |
3 ms |
5004 KB |
Output is correct |
3 |
Correct |
3 ms |
5012 KB |
Output is correct |
4 |
Correct |
3 ms |
5008 KB |
Output is correct |
5 |
Correct |
3 ms |
5076 KB |
Output is correct |
6 |
Correct |
4 ms |
5076 KB |
Output is correct |
7 |
Correct |
4 ms |
5076 KB |
Output is correct |
8 |
Correct |
4 ms |
5076 KB |
Output is correct |
9 |
Correct |
67 ms |
15092 KB |
Output is correct |
10 |
Correct |
106 ms |
16560 KB |
Output is correct |
11 |
Correct |
111 ms |
16540 KB |
Output is correct |
12 |
Correct |
116 ms |
17216 KB |
Output is correct |
13 |
Correct |
87 ms |
14632 KB |
Output is correct |
14 |
Execution timed out |
2043 ms |
15148 KB |
Time limit exceeded |
15 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4948 KB |
Output is correct |
2 |
Correct |
3 ms |
4948 KB |
Output is correct |
3 |
Correct |
3 ms |
5004 KB |
Output is correct |
4 |
Correct |
3 ms |
5012 KB |
Output is correct |
5 |
Correct |
3 ms |
5008 KB |
Output is correct |
6 |
Correct |
3 ms |
5076 KB |
Output is correct |
7 |
Correct |
4 ms |
5076 KB |
Output is correct |
8 |
Correct |
4 ms |
5076 KB |
Output is correct |
9 |
Correct |
4 ms |
5076 KB |
Output is correct |
10 |
Correct |
67 ms |
15092 KB |
Output is correct |
11 |
Correct |
106 ms |
16560 KB |
Output is correct |
12 |
Correct |
111 ms |
16540 KB |
Output is correct |
13 |
Correct |
116 ms |
17216 KB |
Output is correct |
14 |
Correct |
87 ms |
14632 KB |
Output is correct |
15 |
Execution timed out |
2043 ms |
15148 KB |
Time limit exceeded |
16 |
Halted |
0 ms |
0 KB |
- |