/*input
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
*/
#include "swap.h"
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0;i<n;i++)
#define ALL(x) x.begin(),x.end()
#define pii pair<int,int>
#define f first
#define s second
#define MXTO(a,b) a=max(a,b)
#define MNTO(a,b) a=min(a,b)
#define sz(x) (int)x.size()
#define pb push_back
const int maxn=1e5+5;
vector<pair<int,pii>> ed;
int n,m;
vector<pii> g[maxn];
void init(int N, int M,
std::vector<int> U, std::vector<int> V, std::vector<int> W) {
n=N,m=M;
REP(i,M){
ed.pb({W[i],{U[i],V[i]}});
g[U[i]].pb({V[i],W[i]});
g[V[i]].pb({U[i],W[i]});
}
sort(ALL(ed));
}
int par[maxn];
pair<bool,pii> cmp[maxn];
int find(int u){
if(par[u]==u) return u;
return par[u]=find(par[u]);
}
vector<int> v[maxn];
void merge(int a,int b){
int oa=a,ob=b;
a=find(a),b=find(b);
if(a==b){
cmp[a].f=0;
return;
}
par[b]=a;
if(cmp[a].f and cmp[b].f){
if((oa==cmp[a].s.f or oa==cmp[a].s.s) and (ob==cmp[b].s.f or ob==cmp[b].s.s)){
cmp[a].f=1;
if(oa==cmp[a].s.f) cmp[a].s.f=cmp[a].s.s;
if(ob==cmp[b].s.f) cmp[a].s.s=cmp[b].s.s;
else cmp[a].s.s=cmp[b].s.f;
}
else cmp[a].f=0;
}
else cmp[a].f=0;
}
const int INF=0x3f3f3f3f;
int getMinimumFuelCapacity(int x, int y) {
REP(i,n) par[i]=i,v[i].clear(),cmp[i]={1,{i,i}};
int ans=-1;
for(auto a:ed){
merge(a.s.f,a.s.s);
if(find(x)==find(y)){
if(!cmp[find(x)].f){
return a.f;
}
}
}
return -1;
}
Compilation message
swap.cpp: In function 'int getMinimumFuelCapacity(int, int)':
swap.cpp:70:9: warning: unused variable 'ans' [-Wunused-variable]
70 | int ans=-1;
| ^~~
# |
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 |
4 ms |
4948 KB |
Output is correct |
4 |
Correct |
3 ms |
5012 KB |
Output is correct |
5 |
Correct |
3 ms |
5076 KB |
Output is correct |
6 |
Correct |
3 ms |
5076 KB |
Output is correct |
7 |
Correct |
4 ms |
5076 KB |
Output is correct |
8 |
Correct |
3 ms |
5076 KB |
Output is correct |
9 |
Correct |
49 ms |
12376 KB |
Output is correct |
10 |
Correct |
72 ms |
13716 KB |
Output is correct |
11 |
Correct |
85 ms |
13656 KB |
Output is correct |
12 |
Correct |
84 ms |
14168 KB |
Output is correct |
13 |
Correct |
73 ms |
14440 KB |
Output is correct |
14 |
Execution timed out |
2054 ms |
12732 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 |
Execution timed out |
2060 ms |
18456 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 |
4948 KB |
Output is correct |
3 |
Correct |
4 ms |
4948 KB |
Output is correct |
4 |
Correct |
3 ms |
5012 KB |
Output is correct |
5 |
Correct |
3 ms |
5076 KB |
Output is correct |
6 |
Correct |
3 ms |
5076 KB |
Output is correct |
7 |
Correct |
4 ms |
5076 KB |
Output is correct |
8 |
Correct |
3 ms |
5076 KB |
Output is correct |
9 |
Correct |
4 ms |
5008 KB |
Output is correct |
10 |
Correct |
4 ms |
5076 KB |
Output is correct |
11 |
Correct |
3 ms |
5076 KB |
Output is correct |
12 |
Correct |
3 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 |
5020 KB |
Output is correct |
16 |
Correct |
3 ms |
5076 KB |
Output is correct |
17 |
Correct |
4 ms |
5016 KB |
Output is correct |
18 |
Correct |
4 ms |
5020 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 |
5076 KB |
Output is correct |
22 |
Correct |
4 ms |
5076 KB |
Output is correct |
23 |
Correct |
4 ms |
5076 KB |
Output is correct |
24 |
Correct |
5 ms |
5144 KB |
Output is correct |
25 |
Correct |
4 ms |
5076 KB |
Output is correct |
26 |
Correct |
4 ms |
5076 KB |
Output is correct |
27 |
Correct |
3 ms |
5076 KB |
Output is correct |
28 |
Correct |
4 ms |
5148 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
5008 KB |
Output is correct |
2 |
Correct |
3 ms |
4948 KB |
Output is correct |
3 |
Correct |
3 ms |
4948 KB |
Output is correct |
4 |
Correct |
4 ms |
4948 KB |
Output is correct |
5 |
Correct |
3 ms |
5012 KB |
Output is correct |
6 |
Correct |
3 ms |
5076 KB |
Output is correct |
7 |
Correct |
3 ms |
5076 KB |
Output is correct |
8 |
Correct |
4 ms |
5076 KB |
Output is correct |
9 |
Correct |
3 ms |
5076 KB |
Output is correct |
10 |
Correct |
49 ms |
12376 KB |
Output is correct |
11 |
Correct |
72 ms |
13716 KB |
Output is correct |
12 |
Correct |
85 ms |
13656 KB |
Output is correct |
13 |
Correct |
84 ms |
14168 KB |
Output is correct |
14 |
Correct |
73 ms |
14440 KB |
Output is correct |
15 |
Correct |
4 ms |
5076 KB |
Output is correct |
16 |
Correct |
3 ms |
5076 KB |
Output is correct |
17 |
Correct |
3 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 |
5020 KB |
Output is correct |
21 |
Correct |
3 ms |
5076 KB |
Output is correct |
22 |
Correct |
4 ms |
5016 KB |
Output is correct |
23 |
Correct |
4 ms |
5020 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 |
5076 KB |
Output is correct |
27 |
Correct |
4 ms |
5076 KB |
Output is correct |
28 |
Correct |
4 ms |
5076 KB |
Output is correct |
29 |
Correct |
5 ms |
5144 KB |
Output is correct |
30 |
Correct |
4 ms |
5076 KB |
Output is correct |
31 |
Correct |
4 ms |
5076 KB |
Output is correct |
32 |
Correct |
3 ms |
5076 KB |
Output is correct |
33 |
Correct |
4 ms |
5148 KB |
Output is correct |
34 |
Correct |
11 ms |
6484 KB |
Output is correct |
35 |
Correct |
90 ms |
13868 KB |
Output is correct |
36 |
Correct |
79 ms |
13800 KB |
Output is correct |
37 |
Correct |
73 ms |
13752 KB |
Output is correct |
38 |
Correct |
72 ms |
13692 KB |
Output is correct |
39 |
Correct |
83 ms |
13824 KB |
Output is correct |
40 |
Correct |
79 ms |
13100 KB |
Output is correct |
41 |
Correct |
82 ms |
14156 KB |
Output is correct |
42 |
Correct |
78 ms |
13864 KB |
Output is correct |
43 |
Correct |
70 ms |
13980 KB |
Output is correct |
44 |
Correct |
84 ms |
14568 KB |
Output is correct |
45 |
Correct |
119 ms |
18816 KB |
Output is correct |
46 |
Correct |
73 ms |
13752 KB |
Output is correct |
47 |
Correct |
81 ms |
13880 KB |
Output is correct |
48 |
Correct |
96 ms |
14692 KB |
Output is correct |
49 |
Correct |
70 ms |
18200 KB |
Output is correct |
50 |
Correct |
71 ms |
14904 KB |
Output is correct |
51 |
Correct |
94 ms |
16240 KB |
Output is correct |
52 |
Correct |
124 ms |
19712 KB |
Output is correct |
53 |
Correct |
121 ms |
20712 KB |
Output is correct |
54 |
Correct |
151 ms |
22112 KB |
Output is correct |
55 |
Correct |
68 ms |
13876 KB |
Output is correct |
56 |
Correct |
136 ms |
20240 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 |
4 ms |
4948 KB |
Output is correct |
4 |
Correct |
3 ms |
5012 KB |
Output is correct |
5 |
Correct |
3 ms |
5076 KB |
Output is correct |
6 |
Correct |
3 ms |
5076 KB |
Output is correct |
7 |
Correct |
4 ms |
5076 KB |
Output is correct |
8 |
Correct |
3 ms |
5076 KB |
Output is correct |
9 |
Correct |
49 ms |
12376 KB |
Output is correct |
10 |
Correct |
72 ms |
13716 KB |
Output is correct |
11 |
Correct |
85 ms |
13656 KB |
Output is correct |
12 |
Correct |
84 ms |
14168 KB |
Output is correct |
13 |
Correct |
73 ms |
14440 KB |
Output is correct |
14 |
Execution timed out |
2054 ms |
12732 KB |
Time limit exceeded |
15 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
5008 KB |
Output is correct |
2 |
Correct |
3 ms |
4948 KB |
Output is correct |
3 |
Correct |
3 ms |
4948 KB |
Output is correct |
4 |
Correct |
4 ms |
4948 KB |
Output is correct |
5 |
Correct |
3 ms |
5012 KB |
Output is correct |
6 |
Correct |
3 ms |
5076 KB |
Output is correct |
7 |
Correct |
3 ms |
5076 KB |
Output is correct |
8 |
Correct |
4 ms |
5076 KB |
Output is correct |
9 |
Correct |
3 ms |
5076 KB |
Output is correct |
10 |
Correct |
49 ms |
12376 KB |
Output is correct |
11 |
Correct |
72 ms |
13716 KB |
Output is correct |
12 |
Correct |
85 ms |
13656 KB |
Output is correct |
13 |
Correct |
84 ms |
14168 KB |
Output is correct |
14 |
Correct |
73 ms |
14440 KB |
Output is correct |
15 |
Execution timed out |
2054 ms |
12732 KB |
Time limit exceeded |
16 |
Halted |
0 ms |
0 KB |
- |