#include<bits/stdc++.h>
#include "swap.h"
//#include "grader.cpp"
using namespace std;
typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int>vi;
typedef vector<vector<int>>vvi;
typedef vector<ll>vl;
typedef vector<vl> vvl;
typedef pair<int,int>pi;
typedef pair<ll,ll> pl;
typedef vector<pl> vpl;
typedef vector<ld> vld;
typedef pair<ld,ld> pld;
//typedef tree<ll, null_type, less_equal<ll>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
template<typename T> ostream& operator<<(ostream& os, vector<T>& a){os<<"[";for(int i=0; i<ll(a.size()); i++){os << a[i] << ((i!=ll(a.size()-1)?" ":""));}os << "]\n"; return os;}
#define all(x) x.begin(),x.end()
#define YES out("YES")
#define NO out("NO")
#define out(x){cout << x << "\n"; return;}
#define GLHF ios_base::sync_with_stdio(false); cin.tie(NULL)
#define print(x){for(auto ait:x) cout << ait << " "; cout << "\n";}
#define pb push_back
#define umap unordered_map
struct dsu{
vi par,deg;
vector<bool>is_line;
dsu (int n){
par.resize(n);
for(int i=0; i<n; i++)
par[i]=i;
deg.resize(n);
is_line.resize(n,1);
}
int get(int x){return par[x]=(x==par[x]?x:get(par[x]));}
void unite(int u,int v){
bool ok=(deg[u]+1)>2 || (deg[v]+1)>2 || get(u)==get(v);
deg[u]++,deg[v]++;
if(rand()%2)swap(u,v);
if(ok)
is_line[get(u)]=is_line[get(v)]=0;
if(!is_line[get(u)] || !is_line[get(v)])
is_line[get(u)]=is_line[get(v)]=0;
u=get(u),v=get(v);
par[u]=v;
}
};
vector<vector<pi>> g;
vector<bool>vis;
int mx=-1;
bool cyc=1,line=1,star=1;
vvi E;
void init(int n, int M,vi U,vi V,vi W){
g.resize(n);
vis.resize(n);
mx=*max_element(all(W))+1;
for(int i=0; i<M; i++){
g[U[i]].pb({V[i],W[i]});
g[V[i]].pb({U[i],W[i]});
E.pb({W[i],min(U[i],V[i]),max(U[i],V[i])});
}
sort(all(E));
for(int i=0; i<n; i++)
cyc&=g[i].size()==2,line&=g[i].size()<=2;
line&=!cyc;
star&=g[0].size()==n-1 && M==n-1;
}
bool ans;
void dfs(int src,int par,int w){
vis[src]=1;
int cnt=0;
for(pi nbr:g[src])
if(nbr.second<=w)
cnt++;
if(cnt>2)
ans=1;
for(pi nbr:g[src]) {
if(nbr.first==par || nbr.second>w)continue;
if(vis[nbr.first])ans=1;
else dfs(nbr.first,src,w);
}
}
int getMinimumFuelCapacity(int X, int Y){
ll l=1,r=mx,ans=-1;
int n=g.size();
dsu d(n);
for(int i=0; i<E.size(); i++){
d.unite(E[i][1],E[i][2]);
if(d.get(X)==d.get(Y) && !d.is_line[d.get(X)])
return E[i][0];
}
return -1;
}
Compilation message
swap.cpp: In function 'void init(int, int, vi, vi, vi)':
swap.cpp:81:22: warning: comparison of integer expressions of different signedness: 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
81 | star&=g[0].size()==n-1 && M==n-1;
| ~~~~~~~~~~~^~~~~
swap.cpp: In function 'int getMinimumFuelCapacity(int, int)':
swap.cpp:105:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
105 | for(int i=0; i<E.size(); i++){
| ~^~~~~~~~~
swap.cpp:102:8: warning: unused variable 'l' [-Wunused-variable]
102 | ll l=1,r=mx,ans=-1;
| ^
swap.cpp:102:12: warning: unused variable 'r' [-Wunused-variable]
102 | ll l=1,r=mx,ans=-1;
| ^
swap.cpp:102:17: warning: unused variable 'ans' [-Wunused-variable]
102 | ll l=1,r=mx,ans=-1;
| ^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
2 ms |
300 KB |
Output is correct |
5 |
Correct |
2 ms |
332 KB |
Output is correct |
6 |
Correct |
2 ms |
332 KB |
Output is correct |
7 |
Correct |
2 ms |
332 KB |
Output is correct |
8 |
Correct |
2 ms |
332 KB |
Output is correct |
9 |
Correct |
97 ms |
13152 KB |
Output is correct |
10 |
Correct |
167 ms |
14988 KB |
Output is correct |
11 |
Correct |
169 ms |
14844 KB |
Output is correct |
12 |
Correct |
187 ms |
15744 KB |
Output is correct |
13 |
Correct |
182 ms |
15732 KB |
Output is correct |
14 |
Execution timed out |
2028 ms |
13468 KB |
Time limit exceeded |
15 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Execution timed out |
2068 ms |
19256 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
2 ms |
300 KB |
Output is correct |
5 |
Correct |
2 ms |
332 KB |
Output is correct |
6 |
Correct |
2 ms |
332 KB |
Output is correct |
7 |
Correct |
2 ms |
332 KB |
Output is correct |
8 |
Correct |
2 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
204 KB |
Output is correct |
10 |
Correct |
2 ms |
432 KB |
Output is correct |
11 |
Correct |
2 ms |
332 KB |
Output is correct |
12 |
Correct |
2 ms |
316 KB |
Output is correct |
13 |
Correct |
2 ms |
332 KB |
Output is correct |
14 |
Correct |
2 ms |
332 KB |
Output is correct |
15 |
Correct |
2 ms |
444 KB |
Output is correct |
16 |
Correct |
2 ms |
332 KB |
Output is correct |
17 |
Correct |
2 ms |
332 KB |
Output is correct |
18 |
Correct |
3 ms |
332 KB |
Output is correct |
19 |
Correct |
2 ms |
332 KB |
Output is correct |
20 |
Correct |
2 ms |
332 KB |
Output is correct |
21 |
Correct |
2 ms |
460 KB |
Output is correct |
22 |
Correct |
2 ms |
560 KB |
Output is correct |
23 |
Correct |
2 ms |
332 KB |
Output is correct |
24 |
Correct |
4 ms |
460 KB |
Output is correct |
25 |
Correct |
4 ms |
460 KB |
Output is correct |
26 |
Correct |
4 ms |
460 KB |
Output is correct |
27 |
Correct |
2 ms |
332 KB |
Output is correct |
28 |
Correct |
4 ms |
460 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
2 ms |
300 KB |
Output is correct |
6 |
Correct |
2 ms |
332 KB |
Output is correct |
7 |
Correct |
2 ms |
332 KB |
Output is correct |
8 |
Correct |
2 ms |
332 KB |
Output is correct |
9 |
Correct |
2 ms |
332 KB |
Output is correct |
10 |
Correct |
97 ms |
13152 KB |
Output is correct |
11 |
Correct |
167 ms |
14988 KB |
Output is correct |
12 |
Correct |
169 ms |
14844 KB |
Output is correct |
13 |
Correct |
187 ms |
15744 KB |
Output is correct |
14 |
Correct |
182 ms |
15732 KB |
Output is correct |
15 |
Correct |
2 ms |
432 KB |
Output is correct |
16 |
Correct |
2 ms |
332 KB |
Output is correct |
17 |
Correct |
2 ms |
316 KB |
Output is correct |
18 |
Correct |
2 ms |
332 KB |
Output is correct |
19 |
Correct |
2 ms |
332 KB |
Output is correct |
20 |
Correct |
2 ms |
444 KB |
Output is correct |
21 |
Correct |
2 ms |
332 KB |
Output is correct |
22 |
Correct |
2 ms |
332 KB |
Output is correct |
23 |
Correct |
3 ms |
332 KB |
Output is correct |
24 |
Correct |
2 ms |
332 KB |
Output is correct |
25 |
Correct |
2 ms |
332 KB |
Output is correct |
26 |
Correct |
2 ms |
460 KB |
Output is correct |
27 |
Correct |
2 ms |
560 KB |
Output is correct |
28 |
Correct |
2 ms |
332 KB |
Output is correct |
29 |
Correct |
4 ms |
460 KB |
Output is correct |
30 |
Correct |
4 ms |
460 KB |
Output is correct |
31 |
Correct |
4 ms |
460 KB |
Output is correct |
32 |
Correct |
2 ms |
332 KB |
Output is correct |
33 |
Correct |
4 ms |
460 KB |
Output is correct |
34 |
Correct |
12 ms |
2340 KB |
Output is correct |
35 |
Correct |
195 ms |
15348 KB |
Output is correct |
36 |
Correct |
184 ms |
15436 KB |
Output is correct |
37 |
Correct |
202 ms |
15460 KB |
Output is correct |
38 |
Correct |
178 ms |
15208 KB |
Output is correct |
39 |
Correct |
162 ms |
15204 KB |
Output is correct |
40 |
Correct |
140 ms |
14072 KB |
Output is correct |
41 |
Correct |
195 ms |
15836 KB |
Output is correct |
42 |
Correct |
147 ms |
15348 KB |
Output is correct |
43 |
Correct |
188 ms |
15320 KB |
Output is correct |
44 |
Correct |
212 ms |
16212 KB |
Output is correct |
45 |
Correct |
285 ms |
22752 KB |
Output is correct |
46 |
Correct |
197 ms |
15320 KB |
Output is correct |
47 |
Correct |
226 ms |
15448 KB |
Output is correct |
48 |
Correct |
203 ms |
16760 KB |
Output is correct |
49 |
Correct |
147 ms |
20096 KB |
Output is correct |
50 |
Correct |
121 ms |
15248 KB |
Output is correct |
51 |
Correct |
224 ms |
18056 KB |
Output is correct |
52 |
Correct |
301 ms |
24128 KB |
Output is correct |
53 |
Correct |
289 ms |
25444 KB |
Output is correct |
54 |
Correct |
364 ms |
27776 KB |
Output is correct |
55 |
Correct |
149 ms |
15452 KB |
Output is correct |
56 |
Correct |
337 ms |
24608 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
2 ms |
300 KB |
Output is correct |
5 |
Correct |
2 ms |
332 KB |
Output is correct |
6 |
Correct |
2 ms |
332 KB |
Output is correct |
7 |
Correct |
2 ms |
332 KB |
Output is correct |
8 |
Correct |
2 ms |
332 KB |
Output is correct |
9 |
Correct |
97 ms |
13152 KB |
Output is correct |
10 |
Correct |
167 ms |
14988 KB |
Output is correct |
11 |
Correct |
169 ms |
14844 KB |
Output is correct |
12 |
Correct |
187 ms |
15744 KB |
Output is correct |
13 |
Correct |
182 ms |
15732 KB |
Output is correct |
14 |
Execution timed out |
2028 ms |
13468 KB |
Time limit exceeded |
15 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
2 ms |
300 KB |
Output is correct |
6 |
Correct |
2 ms |
332 KB |
Output is correct |
7 |
Correct |
2 ms |
332 KB |
Output is correct |
8 |
Correct |
2 ms |
332 KB |
Output is correct |
9 |
Correct |
2 ms |
332 KB |
Output is correct |
10 |
Correct |
97 ms |
13152 KB |
Output is correct |
11 |
Correct |
167 ms |
14988 KB |
Output is correct |
12 |
Correct |
169 ms |
14844 KB |
Output is correct |
13 |
Correct |
187 ms |
15744 KB |
Output is correct |
14 |
Correct |
182 ms |
15732 KB |
Output is correct |
15 |
Execution timed out |
2028 ms |
13468 KB |
Time limit exceeded |
16 |
Halted |
0 ms |
0 KB |
- |