#include "swap.h"
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 4;
vector<int> sack[maxn];
vector<pair<int,int> > ucond[maxn];
int dsu[maxn],uturn[maxn],adjs[maxn];
void join(int u,int v,int w){
if(dsu[u] != dsu[v]){
if(sack[dsu[v]].size() > sack[dsu[u]].size()){
swap(u,v);
}
int temp = dsu[v];
for(int it : sack[temp]){
sack[dsu[u]].emplace_back(it);
dsu[it] = dsu[u];
ucond[it].emplace_back(dsu[it],w);
}
sack[temp].clear();
}else if(uturn[dsu[u]] == -1){
uturn[dsu[u]] = w;
}
adjs[u]++;
adjs[v]++;
if((adjs[u] > 2 || adjs[v] > 2) && uturn[dsu[u]] == -1){
uturn[dsu[u]] = w;
}
}
void init(int N,int M,vector<int> U,vector<int> V,vector<int> W){
vector<tuple<int,int,int> > edge;
for(int i=0;i<N;i++){
dsu[i] = i;
uturn[i] = -1;
sack[i].emplace_back(i);
ucond[i].emplace_back(i,0);
}
for(int i=0;i<M;i++){
edge.emplace_back(W[i],U[i],V[i]);
}
sort(edge.begin(),edge.end());
for(auto [w,u,v] : edge){
join(u,v,w);
}
for(int i=0;i<N;i++){
reverse(ucond[i].begin(),ucond[i].end());
}
}
int getMinimumFuelCapacity(int X,int Y){
int msize = min(ucond[X].size(),ucond[Y].size()), best = -1;
for(int i=0;i<msize;i++){
if(ucond[X][i].first == ucond[Y][i].first && uturn[ucond[X][i].first] != -1){
if(best == -1){
best = max({ucond[X][i].second,ucond[Y][i].second,uturn[ucond[X][i].first]});
}else{
best = min(best,max({ucond[X][i].second,ucond[Y][i].second,uturn[ucond[X][i].first]}));
}
}
}
return best;
}
Compilation message
swap.cpp: In function 'void init(int, int, std::vector<int>, std::vector<int>, std::vector<int>)':
swap.cpp:43:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
43 | for(auto [w,u,v] : edge){
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
9656 KB |
Output is correct |
2 |
Correct |
7 ms |
9684 KB |
Output is correct |
3 |
Correct |
6 ms |
9700 KB |
Output is correct |
4 |
Correct |
6 ms |
9708 KB |
Output is correct |
5 |
Correct |
6 ms |
9812 KB |
Output is correct |
6 |
Correct |
6 ms |
9812 KB |
Output is correct |
7 |
Correct |
6 ms |
9812 KB |
Output is correct |
8 |
Correct |
7 ms |
9848 KB |
Output is correct |
9 |
Correct |
155 ms |
26792 KB |
Output is correct |
10 |
Correct |
208 ms |
30188 KB |
Output is correct |
11 |
Correct |
172 ms |
29912 KB |
Output is correct |
12 |
Correct |
175 ms |
31088 KB |
Output is correct |
13 |
Correct |
106 ms |
23612 KB |
Output is correct |
14 |
Correct |
140 ms |
26748 KB |
Output is correct |
15 |
Correct |
227 ms |
32200 KB |
Output is correct |
16 |
Correct |
231 ms |
31516 KB |
Output is correct |
17 |
Correct |
241 ms |
32904 KB |
Output is correct |
18 |
Correct |
165 ms |
25216 KB |
Output is correct |
19 |
Correct |
70 ms |
16132 KB |
Output is correct |
20 |
Correct |
238 ms |
35072 KB |
Output is correct |
21 |
Correct |
232 ms |
34648 KB |
Output is correct |
22 |
Correct |
258 ms |
36028 KB |
Output is correct |
23 |
Correct |
170 ms |
28300 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
9656 KB |
Output is correct |
2 |
Correct |
7 ms |
9684 KB |
Output is correct |
3 |
Correct |
151 ms |
22848 KB |
Output is correct |
4 |
Correct |
162 ms |
25844 KB |
Output is correct |
5 |
Correct |
155 ms |
25868 KB |
Output is correct |
6 |
Correct |
154 ms |
25732 KB |
Output is correct |
7 |
Correct |
180 ms |
25940 KB |
Output is correct |
8 |
Correct |
156 ms |
25500 KB |
Output is correct |
9 |
Correct |
153 ms |
25700 KB |
Output is correct |
10 |
Correct |
164 ms |
25376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
9656 KB |
Output is correct |
2 |
Correct |
7 ms |
9684 KB |
Output is correct |
3 |
Correct |
6 ms |
9700 KB |
Output is correct |
4 |
Correct |
6 ms |
9708 KB |
Output is correct |
5 |
Correct |
6 ms |
9812 KB |
Output is correct |
6 |
Correct |
6 ms |
9812 KB |
Output is correct |
7 |
Correct |
6 ms |
9812 KB |
Output is correct |
8 |
Correct |
7 ms |
9848 KB |
Output is correct |
9 |
Correct |
8 ms |
9684 KB |
Output is correct |
10 |
Correct |
6 ms |
9812 KB |
Output is correct |
11 |
Incorrect |
6 ms |
9840 KB |
Output isn't correct |
12 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
9684 KB |
Output is correct |
2 |
Correct |
5 ms |
9656 KB |
Output is correct |
3 |
Correct |
7 ms |
9684 KB |
Output is correct |
4 |
Correct |
6 ms |
9700 KB |
Output is correct |
5 |
Correct |
6 ms |
9708 KB |
Output is correct |
6 |
Correct |
6 ms |
9812 KB |
Output is correct |
7 |
Correct |
6 ms |
9812 KB |
Output is correct |
8 |
Correct |
6 ms |
9812 KB |
Output is correct |
9 |
Correct |
7 ms |
9848 KB |
Output is correct |
10 |
Correct |
155 ms |
26792 KB |
Output is correct |
11 |
Correct |
208 ms |
30188 KB |
Output is correct |
12 |
Correct |
172 ms |
29912 KB |
Output is correct |
13 |
Correct |
175 ms |
31088 KB |
Output is correct |
14 |
Correct |
106 ms |
23612 KB |
Output is correct |
15 |
Correct |
6 ms |
9812 KB |
Output is correct |
16 |
Incorrect |
6 ms |
9840 KB |
Output isn't correct |
17 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
9656 KB |
Output is correct |
2 |
Correct |
7 ms |
9684 KB |
Output is correct |
3 |
Correct |
6 ms |
9700 KB |
Output is correct |
4 |
Correct |
6 ms |
9708 KB |
Output is correct |
5 |
Correct |
6 ms |
9812 KB |
Output is correct |
6 |
Correct |
6 ms |
9812 KB |
Output is correct |
7 |
Correct |
6 ms |
9812 KB |
Output is correct |
8 |
Correct |
7 ms |
9848 KB |
Output is correct |
9 |
Correct |
155 ms |
26792 KB |
Output is correct |
10 |
Correct |
208 ms |
30188 KB |
Output is correct |
11 |
Correct |
172 ms |
29912 KB |
Output is correct |
12 |
Correct |
175 ms |
31088 KB |
Output is correct |
13 |
Correct |
106 ms |
23612 KB |
Output is correct |
14 |
Correct |
140 ms |
26748 KB |
Output is correct |
15 |
Correct |
227 ms |
32200 KB |
Output is correct |
16 |
Correct |
231 ms |
31516 KB |
Output is correct |
17 |
Correct |
241 ms |
32904 KB |
Output is correct |
18 |
Correct |
165 ms |
25216 KB |
Output is correct |
19 |
Correct |
151 ms |
22848 KB |
Output is correct |
20 |
Correct |
162 ms |
25844 KB |
Output is correct |
21 |
Correct |
155 ms |
25868 KB |
Output is correct |
22 |
Correct |
154 ms |
25732 KB |
Output is correct |
23 |
Correct |
180 ms |
25940 KB |
Output is correct |
24 |
Correct |
156 ms |
25500 KB |
Output is correct |
25 |
Correct |
153 ms |
25700 KB |
Output is correct |
26 |
Correct |
164 ms |
25376 KB |
Output is correct |
27 |
Correct |
6 ms |
9812 KB |
Output is correct |
28 |
Incorrect |
6 ms |
9840 KB |
Output isn't correct |
29 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
9684 KB |
Output is correct |
2 |
Correct |
5 ms |
9656 KB |
Output is correct |
3 |
Correct |
7 ms |
9684 KB |
Output is correct |
4 |
Correct |
6 ms |
9700 KB |
Output is correct |
5 |
Correct |
6 ms |
9708 KB |
Output is correct |
6 |
Correct |
6 ms |
9812 KB |
Output is correct |
7 |
Correct |
6 ms |
9812 KB |
Output is correct |
8 |
Correct |
6 ms |
9812 KB |
Output is correct |
9 |
Correct |
7 ms |
9848 KB |
Output is correct |
10 |
Correct |
155 ms |
26792 KB |
Output is correct |
11 |
Correct |
208 ms |
30188 KB |
Output is correct |
12 |
Correct |
172 ms |
29912 KB |
Output is correct |
13 |
Correct |
175 ms |
31088 KB |
Output is correct |
14 |
Correct |
106 ms |
23612 KB |
Output is correct |
15 |
Correct |
140 ms |
26748 KB |
Output is correct |
16 |
Correct |
227 ms |
32200 KB |
Output is correct |
17 |
Correct |
231 ms |
31516 KB |
Output is correct |
18 |
Correct |
241 ms |
32904 KB |
Output is correct |
19 |
Correct |
165 ms |
25216 KB |
Output is correct |
20 |
Correct |
151 ms |
22848 KB |
Output is correct |
21 |
Correct |
162 ms |
25844 KB |
Output is correct |
22 |
Correct |
155 ms |
25868 KB |
Output is correct |
23 |
Correct |
154 ms |
25732 KB |
Output is correct |
24 |
Correct |
180 ms |
25940 KB |
Output is correct |
25 |
Correct |
156 ms |
25500 KB |
Output is correct |
26 |
Correct |
153 ms |
25700 KB |
Output is correct |
27 |
Correct |
164 ms |
25376 KB |
Output is correct |
28 |
Correct |
6 ms |
9812 KB |
Output is correct |
29 |
Incorrect |
6 ms |
9840 KB |
Output isn't correct |
30 |
Halted |
0 ms |
0 KB |
- |