#include "swap.h"
#include <bits/stdc++.h>
#define ll long long
#define f first
#define s second
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pb push_back
#define epb emplace_back
#define ull unsigned ll
#include <vector>
/*
5 6
0 1 4
0 2 4
1 2 1
1 3 2
1 4 10
2 3 3
3
1 2
2 4
0 1
*/
using namespace std;
const int nmax = 1000000;
vector <vector <pii> > g(nmax);
vector <vector <int> > cmp(nmax);
vector <pii> par[nmax];
int val[nmax];
int l[nmax], r[nmax];
void make_set(int v){
par[v].pb({v, 0});
cmp[v].pb(v);
val[v] = 1e9 + 1;
l[v] = r[v] = v;
}
void union_sets(int a, int b, int len){
if(par[a].back().f == par[b].back().f){
if(val[a] == 1e9 +1){
int x = par[a].back().f;
for(int to : cmp[x]){
val[to] = len;
}
}
return;
}
int x = par[a].back().f, y = par[b].back().f;
if(cmp[x].size() < cmp[y].size())
swap(x, y), swap(a, b);
for(int to : cmp[y])
cmp[x].pb(to), par[to].pb({x, len});
if(val[x] == 1e9 + 1 || val[y] == 1e9 + 1){
int mn = min(val[x], val[y]);
if(mn != 1e9 + 1){
for(int to : cmp[x])
val[to] = min(val[to], len);
return;}
}
if(val[x] != 1e9 + 1 && val[y] != 1e9 + 1){
return;
}
if(l[x] == a && l[y] == b){
l[x] = r[y];
return;
}
if(l[x] == a && r[y] == b){
l[x] = l[y];
return;
}
if(r[x] == a && l[y] == b){
r[x] = r[y];
return;
}
if(r[x] == a && r[y] == b){
r[x] = l[y];
return;
}
for(int to : cmp[x])
val[to] = min(val[to], len);
}
void init(int N, int M,
std::vector<int> U, std::vector<int> V, std::vector<int> W) {
int n = N;
vector <pair <int, pii> > ed;
for(int i = 0; i < n; i++)
make_set(i);
for(int i = 0; i < M; i++){
ed.pb({W[i], {U[i], V[i]}});
}
sort(ed.begin(), ed.end());
for(int i = 0; i < ed.size(); i++){
union_sets(ed[i].s.f, ed[i].s.s, ed[i].f);
//cout << 1;
}
}
int getMinimumFuelCapacity(int X, int Y) {
if(val[X] == 1e9 + 1)
return -1;
int x = X, y = Y;
int sz = par[x].size() - 1;
int sz2 = par[y].size() - 1;
int ans = 1e9 + 1;
while(sz >= 0 && sz2 >= 0){
if(par[x][sz].f== par[y][sz2].f)
ans = min(ans, max(par[x][sz].s, par[y][sz2].s));
sz--;
sz2--;
}
int u = max(min(val[X],val[y]), ans);
if(u == 1e9 + 1)
u = -1;
return u;
}
Compilation message
swap.cpp: In function 'void init(int, int, std::vector<int>, std::vector<int>, std::vector<int>)':
swap.cpp:104:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, std::pair<int, int> > >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
104 | for(int i = 0; i < ed.size(); i++){
| ~~^~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
37 ms |
70724 KB |
Output is correct |
2 |
Correct |
35 ms |
70700 KB |
Output is correct |
3 |
Correct |
33 ms |
70672 KB |
Output is correct |
4 |
Correct |
33 ms |
70868 KB |
Output is correct |
5 |
Correct |
34 ms |
70892 KB |
Output is correct |
6 |
Correct |
34 ms |
70932 KB |
Output is correct |
7 |
Correct |
35 ms |
70948 KB |
Output is correct |
8 |
Correct |
37 ms |
70912 KB |
Output is correct |
9 |
Correct |
139 ms |
87836 KB |
Output is correct |
10 |
Correct |
180 ms |
91332 KB |
Output is correct |
11 |
Correct |
194 ms |
90956 KB |
Output is correct |
12 |
Correct |
185 ms |
92072 KB |
Output is correct |
13 |
Correct |
136 ms |
84680 KB |
Output is correct |
14 |
Correct |
166 ms |
87852 KB |
Output is correct |
15 |
Correct |
266 ms |
93284 KB |
Output is correct |
16 |
Correct |
240 ms |
92608 KB |
Output is correct |
17 |
Correct |
243 ms |
94056 KB |
Output is correct |
18 |
Correct |
187 ms |
86236 KB |
Output is correct |
19 |
Correct |
106 ms |
77284 KB |
Output is correct |
20 |
Correct |
255 ms |
93504 KB |
Output is correct |
21 |
Correct |
263 ms |
93064 KB |
Output is correct |
22 |
Correct |
274 ms |
94328 KB |
Output is correct |
23 |
Correct |
190 ms |
86664 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
37 ms |
70724 KB |
Output is correct |
2 |
Correct |
35 ms |
70700 KB |
Output is correct |
3 |
Execution timed out |
2051 ms |
83260 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
37 ms |
70724 KB |
Output is correct |
2 |
Correct |
35 ms |
70700 KB |
Output is correct |
3 |
Correct |
33 ms |
70672 KB |
Output is correct |
4 |
Correct |
33 ms |
70868 KB |
Output is correct |
5 |
Correct |
34 ms |
70892 KB |
Output is correct |
6 |
Correct |
34 ms |
70932 KB |
Output is correct |
7 |
Correct |
35 ms |
70948 KB |
Output is correct |
8 |
Correct |
37 ms |
70912 KB |
Output is correct |
9 |
Correct |
34 ms |
70720 KB |
Output is correct |
10 |
Correct |
33 ms |
70848 KB |
Output is correct |
11 |
Correct |
34 ms |
70844 KB |
Output is correct |
12 |
Correct |
34 ms |
70948 KB |
Output is correct |
13 |
Correct |
34 ms |
70860 KB |
Output is correct |
14 |
Correct |
36 ms |
70868 KB |
Output is correct |
15 |
Correct |
35 ms |
70884 KB |
Output is correct |
16 |
Correct |
36 ms |
70980 KB |
Output is correct |
17 |
Correct |
45 ms |
70892 KB |
Output is correct |
18 |
Correct |
34 ms |
70936 KB |
Output is correct |
19 |
Correct |
35 ms |
70780 KB |
Output is correct |
20 |
Correct |
35 ms |
70844 KB |
Output is correct |
21 |
Correct |
36 ms |
70804 KB |
Output is correct |
22 |
Correct |
34 ms |
70776 KB |
Output is correct |
23 |
Correct |
36 ms |
70896 KB |
Output is correct |
24 |
Correct |
36 ms |
70896 KB |
Output is correct |
25 |
Correct |
41 ms |
70864 KB |
Output is correct |
26 |
Correct |
37 ms |
70988 KB |
Output is correct |
27 |
Correct |
37 ms |
70808 KB |
Output is correct |
28 |
Correct |
36 ms |
70928 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
34 ms |
70720 KB |
Output is correct |
2 |
Correct |
37 ms |
70724 KB |
Output is correct |
3 |
Correct |
35 ms |
70700 KB |
Output is correct |
4 |
Correct |
33 ms |
70672 KB |
Output is correct |
5 |
Correct |
33 ms |
70868 KB |
Output is correct |
6 |
Correct |
34 ms |
70892 KB |
Output is correct |
7 |
Correct |
34 ms |
70932 KB |
Output is correct |
8 |
Correct |
35 ms |
70948 KB |
Output is correct |
9 |
Correct |
37 ms |
70912 KB |
Output is correct |
10 |
Correct |
139 ms |
87836 KB |
Output is correct |
11 |
Correct |
180 ms |
91332 KB |
Output is correct |
12 |
Correct |
194 ms |
90956 KB |
Output is correct |
13 |
Correct |
185 ms |
92072 KB |
Output is correct |
14 |
Correct |
136 ms |
84680 KB |
Output is correct |
15 |
Correct |
33 ms |
70848 KB |
Output is correct |
16 |
Correct |
34 ms |
70844 KB |
Output is correct |
17 |
Correct |
34 ms |
70948 KB |
Output is correct |
18 |
Correct |
34 ms |
70860 KB |
Output is correct |
19 |
Correct |
36 ms |
70868 KB |
Output is correct |
20 |
Correct |
35 ms |
70884 KB |
Output is correct |
21 |
Correct |
36 ms |
70980 KB |
Output is correct |
22 |
Correct |
45 ms |
70892 KB |
Output is correct |
23 |
Correct |
34 ms |
70936 KB |
Output is correct |
24 |
Correct |
35 ms |
70780 KB |
Output is correct |
25 |
Correct |
35 ms |
70844 KB |
Output is correct |
26 |
Correct |
36 ms |
70804 KB |
Output is correct |
27 |
Correct |
34 ms |
70776 KB |
Output is correct |
28 |
Correct |
36 ms |
70896 KB |
Output is correct |
29 |
Correct |
36 ms |
70896 KB |
Output is correct |
30 |
Correct |
41 ms |
70864 KB |
Output is correct |
31 |
Correct |
37 ms |
70988 KB |
Output is correct |
32 |
Correct |
37 ms |
70808 KB |
Output is correct |
33 |
Correct |
36 ms |
70928 KB |
Output is correct |
34 |
Correct |
48 ms |
73296 KB |
Output is correct |
35 |
Correct |
206 ms |
91972 KB |
Output is correct |
36 |
Correct |
188 ms |
91832 KB |
Output is correct |
37 |
Correct |
184 ms |
91372 KB |
Output is correct |
38 |
Correct |
213 ms |
90476 KB |
Output is correct |
39 |
Correct |
193 ms |
90076 KB |
Output is correct |
40 |
Correct |
192 ms |
88144 KB |
Output is correct |
41 |
Correct |
187 ms |
92480 KB |
Output is correct |
42 |
Correct |
180 ms |
92424 KB |
Output is correct |
43 |
Execution timed out |
2065 ms |
82244 KB |
Time limit exceeded |
44 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
37 ms |
70724 KB |
Output is correct |
2 |
Correct |
35 ms |
70700 KB |
Output is correct |
3 |
Correct |
33 ms |
70672 KB |
Output is correct |
4 |
Correct |
33 ms |
70868 KB |
Output is correct |
5 |
Correct |
34 ms |
70892 KB |
Output is correct |
6 |
Correct |
34 ms |
70932 KB |
Output is correct |
7 |
Correct |
35 ms |
70948 KB |
Output is correct |
8 |
Correct |
37 ms |
70912 KB |
Output is correct |
9 |
Correct |
139 ms |
87836 KB |
Output is correct |
10 |
Correct |
180 ms |
91332 KB |
Output is correct |
11 |
Correct |
194 ms |
90956 KB |
Output is correct |
12 |
Correct |
185 ms |
92072 KB |
Output is correct |
13 |
Correct |
136 ms |
84680 KB |
Output is correct |
14 |
Correct |
166 ms |
87852 KB |
Output is correct |
15 |
Correct |
266 ms |
93284 KB |
Output is correct |
16 |
Correct |
240 ms |
92608 KB |
Output is correct |
17 |
Correct |
243 ms |
94056 KB |
Output is correct |
18 |
Correct |
187 ms |
86236 KB |
Output is correct |
19 |
Execution timed out |
2051 ms |
83260 KB |
Time limit exceeded |
20 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
34 ms |
70720 KB |
Output is correct |
2 |
Correct |
37 ms |
70724 KB |
Output is correct |
3 |
Correct |
35 ms |
70700 KB |
Output is correct |
4 |
Correct |
33 ms |
70672 KB |
Output is correct |
5 |
Correct |
33 ms |
70868 KB |
Output is correct |
6 |
Correct |
34 ms |
70892 KB |
Output is correct |
7 |
Correct |
34 ms |
70932 KB |
Output is correct |
8 |
Correct |
35 ms |
70948 KB |
Output is correct |
9 |
Correct |
37 ms |
70912 KB |
Output is correct |
10 |
Correct |
139 ms |
87836 KB |
Output is correct |
11 |
Correct |
180 ms |
91332 KB |
Output is correct |
12 |
Correct |
194 ms |
90956 KB |
Output is correct |
13 |
Correct |
185 ms |
92072 KB |
Output is correct |
14 |
Correct |
136 ms |
84680 KB |
Output is correct |
15 |
Correct |
166 ms |
87852 KB |
Output is correct |
16 |
Correct |
266 ms |
93284 KB |
Output is correct |
17 |
Correct |
240 ms |
92608 KB |
Output is correct |
18 |
Correct |
243 ms |
94056 KB |
Output is correct |
19 |
Correct |
187 ms |
86236 KB |
Output is correct |
20 |
Execution timed out |
2051 ms |
83260 KB |
Time limit exceeded |
21 |
Halted |
0 ms |
0 KB |
- |