#include "swap.h"
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
const int N=100050;
const int inf=1e9+7;
int myc[N],dst[N],tme[N],deg[N];
vector<int> cmp[N],my[N];
void mrg(int u,int v,int w){
deg[u]++;deg[v]++;
if(myc[u]==myc[v]){
int c=myc[u];
tme[c]=min(tme[c],w);
}else{
int c1=myc[u],c2=myc[v];
if(cmp[c1].size()>cmp[c2].size())swap(c1,c2);
tme[c2]=min(tme[c2],max(tme[c1],w));
dst[c1]=w;
if(deg[u]>2||deg[v]>2)tme[c2]=min(tme[c2],w);
for(int i:cmp[c1]){
myc[i]=c2;
my[i].pb(c2);
cmp[c2].pb(i);
}
cmp[c1].clear();
}
}
void init(int n,int m,vector<int> u,vector<int> v,vector<int> w){
vector<int> idx;
for(int i=0;i<m;i++)idx.pb(i);
sort(idx.begin(),idx.end(),[&](int i,int j){return w[i]<w[j];});
for(int i=0;i<n;i++){
myc[i]=i;
cmp[i]={i};
dst[i]=inf;
tme[i]=inf;
my[i].pb(i);
}
for(int i:idx){
mrg(u[i],v[i],w[i]);
}
}
int getMinimumFuelCapacity(int x,int y){
int i=0,j=0,mn=0;
while(i<my[x].size()&&j<my[y].size()&&my[x][i]!=my[y][j]){
if(dst[my[x][i]]<dst[my[y][j]])mn=max(mn,dst[my[x][i]]),i++;
else mn=max(mn,dst[my[y][j]]),j++;
}
if(i==my[x].size()||j==my[y].size())return -1;
int ans=inf;
while(i<my[x].size()){
ans=min(ans,tme[my[x][i]]);
assert(j<my[y].size()&&my[x][i]==my[y][j]);
i++;j++;
}
ans=max(ans,mn);
return ans==inf?-1:ans;
}
Compilation message
swap.cpp: In function 'int getMinimumFuelCapacity(int, int)':
swap.cpp:48:9: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
48 | while(i<my[x].size()&&j<my[y].size()&&my[x][i]!=my[y][j]){
| ~^~~~~~~~~~~~~
swap.cpp:48:25: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
48 | while(i<my[x].size()&&j<my[y].size()&&my[x][i]!=my[y][j]){
| ~^~~~~~~~~~~~~
swap.cpp:52:6: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
52 | if(i==my[x].size()||j==my[y].size())return -1;
| ~^~~~~~~~~~~~~~
swap.cpp:52:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
52 | if(i==my[x].size()||j==my[y].size())return -1;
| ~^~~~~~~~~~~~~~
swap.cpp:54:9: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
54 | while(i<my[x].size()){
| ~^~~~~~~~~~~~~
In file included from /usr/include/c++/9/cassert:44,
from /usr/include/x86_64-linux-gnu/c++/9/bits/stdc++.h:33,
from swap.cpp:2:
swap.cpp:56:11: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
56 | assert(j<my[y].size()&&my[x][i]==my[y][j]);
| ~^~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4992 KB |
Output is correct |
2 |
Correct |
3 ms |
4992 KB |
Output is correct |
3 |
Correct |
4 ms |
4992 KB |
Output is correct |
4 |
Correct |
4 ms |
5120 KB |
Output is correct |
5 |
Correct |
4 ms |
5120 KB |
Output is correct |
6 |
Correct |
4 ms |
5248 KB |
Output is correct |
7 |
Correct |
4 ms |
5120 KB |
Output is correct |
8 |
Correct |
4 ms |
5120 KB |
Output is correct |
9 |
Correct |
169 ms |
18800 KB |
Output is correct |
10 |
Correct |
209 ms |
21104 KB |
Output is correct |
11 |
Correct |
211 ms |
20900 KB |
Output is correct |
12 |
Correct |
227 ms |
21876 KB |
Output is correct |
13 |
Correct |
135 ms |
16880 KB |
Output is correct |
14 |
Correct |
182 ms |
18672 KB |
Output is correct |
15 |
Correct |
351 ms |
23152 KB |
Output is correct |
16 |
Correct |
328 ms |
22512 KB |
Output is correct |
17 |
Correct |
360 ms |
23792 KB |
Output is correct |
18 |
Correct |
241 ms |
18160 KB |
Output is correct |
19 |
Correct |
102 ms |
11000 KB |
Output is correct |
20 |
Correct |
336 ms |
24176 KB |
Output is correct |
21 |
Correct |
347 ms |
24000 KB |
Output is correct |
22 |
Correct |
369 ms |
24912 KB |
Output is correct |
23 |
Correct |
248 ms |
19232 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4992 KB |
Output is correct |
2 |
Correct |
3 ms |
4992 KB |
Output is correct |
3 |
Correct |
210 ms |
18220 KB |
Output is correct |
4 |
Correct |
225 ms |
18640 KB |
Output is correct |
5 |
Correct |
214 ms |
18576 KB |
Output is correct |
6 |
Correct |
212 ms |
18524 KB |
Output is correct |
7 |
Correct |
213 ms |
18544 KB |
Output is correct |
8 |
Correct |
206 ms |
18228 KB |
Output is correct |
9 |
Correct |
216 ms |
18496 KB |
Output is correct |
10 |
Correct |
210 ms |
18112 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4992 KB |
Output is correct |
2 |
Correct |
3 ms |
4992 KB |
Output is correct |
3 |
Correct |
3 ms |
4992 KB |
Output is correct |
4 |
Correct |
4 ms |
4992 KB |
Output is correct |
5 |
Correct |
4 ms |
5120 KB |
Output is correct |
6 |
Correct |
4 ms |
5120 KB |
Output is correct |
7 |
Correct |
4 ms |
5248 KB |
Output is correct |
8 |
Correct |
4 ms |
5120 KB |
Output is correct |
9 |
Correct |
4 ms |
5120 KB |
Output is correct |
10 |
Correct |
4 ms |
5120 KB |
Output is correct |
11 |
Correct |
4 ms |
5248 KB |
Output is correct |
12 |
Correct |
5 ms |
5120 KB |
Output is correct |
13 |
Correct |
4 ms |
5120 KB |
Output is correct |
14 |
Correct |
4 ms |
5120 KB |
Output is correct |
15 |
Incorrect |
5 ms |
5120 KB |
Output isn't correct |
16 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4992 KB |
Output is correct |
2 |
Correct |
3 ms |
4992 KB |
Output is correct |
3 |
Correct |
3 ms |
4992 KB |
Output is correct |
4 |
Correct |
4 ms |
4992 KB |
Output is correct |
5 |
Correct |
4 ms |
5120 KB |
Output is correct |
6 |
Correct |
4 ms |
5120 KB |
Output is correct |
7 |
Correct |
4 ms |
5248 KB |
Output is correct |
8 |
Correct |
4 ms |
5120 KB |
Output is correct |
9 |
Correct |
4 ms |
5120 KB |
Output is correct |
10 |
Correct |
169 ms |
18800 KB |
Output is correct |
11 |
Correct |
209 ms |
21104 KB |
Output is correct |
12 |
Correct |
211 ms |
20900 KB |
Output is correct |
13 |
Correct |
227 ms |
21876 KB |
Output is correct |
14 |
Correct |
135 ms |
16880 KB |
Output is correct |
15 |
Correct |
4 ms |
5120 KB |
Output is correct |
16 |
Correct |
4 ms |
5248 KB |
Output is correct |
17 |
Correct |
5 ms |
5120 KB |
Output is correct |
18 |
Correct |
4 ms |
5120 KB |
Output is correct |
19 |
Correct |
4 ms |
5120 KB |
Output is correct |
20 |
Incorrect |
5 ms |
5120 KB |
Output isn't correct |
21 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4992 KB |
Output is correct |
2 |
Correct |
3 ms |
4992 KB |
Output is correct |
3 |
Correct |
4 ms |
4992 KB |
Output is correct |
4 |
Correct |
4 ms |
5120 KB |
Output is correct |
5 |
Correct |
4 ms |
5120 KB |
Output is correct |
6 |
Correct |
4 ms |
5248 KB |
Output is correct |
7 |
Correct |
4 ms |
5120 KB |
Output is correct |
8 |
Correct |
4 ms |
5120 KB |
Output is correct |
9 |
Correct |
169 ms |
18800 KB |
Output is correct |
10 |
Correct |
209 ms |
21104 KB |
Output is correct |
11 |
Correct |
211 ms |
20900 KB |
Output is correct |
12 |
Correct |
227 ms |
21876 KB |
Output is correct |
13 |
Correct |
135 ms |
16880 KB |
Output is correct |
14 |
Correct |
182 ms |
18672 KB |
Output is correct |
15 |
Correct |
351 ms |
23152 KB |
Output is correct |
16 |
Correct |
328 ms |
22512 KB |
Output is correct |
17 |
Correct |
360 ms |
23792 KB |
Output is correct |
18 |
Correct |
241 ms |
18160 KB |
Output is correct |
19 |
Correct |
210 ms |
18220 KB |
Output is correct |
20 |
Correct |
225 ms |
18640 KB |
Output is correct |
21 |
Correct |
214 ms |
18576 KB |
Output is correct |
22 |
Correct |
212 ms |
18524 KB |
Output is correct |
23 |
Correct |
213 ms |
18544 KB |
Output is correct |
24 |
Correct |
206 ms |
18228 KB |
Output is correct |
25 |
Correct |
216 ms |
18496 KB |
Output is correct |
26 |
Correct |
210 ms |
18112 KB |
Output is correct |
27 |
Correct |
4 ms |
5120 KB |
Output is correct |
28 |
Correct |
4 ms |
5248 KB |
Output is correct |
29 |
Correct |
5 ms |
5120 KB |
Output is correct |
30 |
Correct |
4 ms |
5120 KB |
Output is correct |
31 |
Correct |
4 ms |
5120 KB |
Output is correct |
32 |
Incorrect |
5 ms |
5120 KB |
Output isn't correct |
33 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4992 KB |
Output is correct |
2 |
Correct |
3 ms |
4992 KB |
Output is correct |
3 |
Correct |
3 ms |
4992 KB |
Output is correct |
4 |
Correct |
4 ms |
4992 KB |
Output is correct |
5 |
Correct |
4 ms |
5120 KB |
Output is correct |
6 |
Correct |
4 ms |
5120 KB |
Output is correct |
7 |
Correct |
4 ms |
5248 KB |
Output is correct |
8 |
Correct |
4 ms |
5120 KB |
Output is correct |
9 |
Correct |
4 ms |
5120 KB |
Output is correct |
10 |
Correct |
169 ms |
18800 KB |
Output is correct |
11 |
Correct |
209 ms |
21104 KB |
Output is correct |
12 |
Correct |
211 ms |
20900 KB |
Output is correct |
13 |
Correct |
227 ms |
21876 KB |
Output is correct |
14 |
Correct |
135 ms |
16880 KB |
Output is correct |
15 |
Correct |
182 ms |
18672 KB |
Output is correct |
16 |
Correct |
351 ms |
23152 KB |
Output is correct |
17 |
Correct |
328 ms |
22512 KB |
Output is correct |
18 |
Correct |
360 ms |
23792 KB |
Output is correct |
19 |
Correct |
241 ms |
18160 KB |
Output is correct |
20 |
Correct |
210 ms |
18220 KB |
Output is correct |
21 |
Correct |
225 ms |
18640 KB |
Output is correct |
22 |
Correct |
214 ms |
18576 KB |
Output is correct |
23 |
Correct |
212 ms |
18524 KB |
Output is correct |
24 |
Correct |
213 ms |
18544 KB |
Output is correct |
25 |
Correct |
206 ms |
18228 KB |
Output is correct |
26 |
Correct |
216 ms |
18496 KB |
Output is correct |
27 |
Correct |
210 ms |
18112 KB |
Output is correct |
28 |
Correct |
4 ms |
5120 KB |
Output is correct |
29 |
Correct |
4 ms |
5248 KB |
Output is correct |
30 |
Correct |
5 ms |
5120 KB |
Output is correct |
31 |
Correct |
4 ms |
5120 KB |
Output is correct |
32 |
Correct |
4 ms |
5120 KB |
Output is correct |
33 |
Incorrect |
5 ms |
5120 KB |
Output isn't correct |
34 |
Halted |
0 ms |
0 KB |
- |