#include "swap.h"
#include <bits/stdc++.h>
// #include "grader.cpp"
using namespace std;
vector<vector<pair<int,int>>>adj;
int mx=0,n=0;
void init(int N, int m,std::vector<int> u, std::vector<int> v, std::vector<int> w) {
adj.resize(N+1);
for(int i=0;i<m;i++)
{
adj[u[i]].push_back({v[i],w[i]});
adj[v[i]].push_back({u[i],w[i]});
mx=max(mx,w[i]);
}
n=N;
}
vector<vector<int>>newadj;
vector<int>vs(n+1);
bool check(int node,int parent)
{
// cout<<node<<" "<<parent<<endl;
int cnt=0;
if(vs[node]==true)return 1;
vs[node]=true;
for(auto i:newadj[node])
{
if(i==parent)continue;
cnt++;
}
if(cnt>1&&parent!=-1)return 1;
else
{
int lol=0;
for(auto i:newadj[node])
{
if(i==parent)continue;
lol|=check(i,node);
}
return lol;
}
}
bool findy(int node,int y)
{
vs[node]=true;
if(node==y)return 1;
int lol=0;
for(auto i:newadj[node])
{
if(!vs[i])
lol|=findy(i,y);
}
return lol;
}
int getMinimumFuelCapacity(int x, int y) {
int l=1,r=mx;
int ans=-1;
newadj.resize(n+1);
for(int i=1;i<=n;i++)vs[i]=0;
while(l<=r){
int mid=(l+r)/2;
for(int i=0;i<n;i++)
for(auto j:adj[i])
if(j.second<=mid)
newadj[i].push_back(j.first);
int node=-1;
// cout<<"HI"<<endl;
int e=check(x,-1);
for(int i=0;i<n;i++)vs[i]=0;
int ee=findy(x,y);
if(e&&ee)
{
ans=mid;
r=mid-1;
}
else l=mid+1;
for(int i=0;i<n;i++)
{
vs[i]=0;
newadj[i].clear();
}
}
return ans;
}
Compilation message
swap.cpp: In function 'int getMinimumFuelCapacity(int, int)':
swap.cpp:66:13: warning: unused variable 'node' [-Wunused-variable]
66 | int node=-1;
| ^~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
440 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
3 ms |
600 KB |
Output is correct |
6 |
Correct |
3 ms |
348 KB |
Output is correct |
7 |
Correct |
3 ms |
604 KB |
Output is correct |
8 |
Correct |
4 ms |
596 KB |
Output is correct |
9 |
Runtime error |
80 ms |
21660 KB |
Execution killed with signal 6 |
10 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
440 KB |
Output is correct |
3 |
Runtime error |
68 ms |
27800 KB |
Execution killed with signal 6 |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
440 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
3 ms |
600 KB |
Output is correct |
6 |
Correct |
3 ms |
348 KB |
Output is correct |
7 |
Correct |
3 ms |
604 KB |
Output is correct |
8 |
Correct |
4 ms |
596 KB |
Output is correct |
9 |
Correct |
0 ms |
432 KB |
Output is correct |
10 |
Correct |
2 ms |
348 KB |
Output is correct |
11 |
Correct |
2 ms |
604 KB |
Output is correct |
12 |
Correct |
2 ms |
348 KB |
Output is correct |
13 |
Correct |
2 ms |
348 KB |
Output is correct |
14 |
Correct |
2 ms |
348 KB |
Output is correct |
15 |
Correct |
2 ms |
348 KB |
Output is correct |
16 |
Correct |
3 ms |
604 KB |
Output is correct |
17 |
Correct |
2 ms |
344 KB |
Output is correct |
18 |
Correct |
3 ms |
348 KB |
Output is correct |
19 |
Correct |
2 ms |
348 KB |
Output is correct |
20 |
Correct |
2 ms |
348 KB |
Output is correct |
21 |
Correct |
2 ms |
348 KB |
Output is correct |
22 |
Correct |
2 ms |
484 KB |
Output is correct |
23 |
Correct |
2 ms |
348 KB |
Output is correct |
24 |
Runtime error |
3 ms |
740 KB |
Execution killed with signal 6 |
25 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
432 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
440 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
3 ms |
600 KB |
Output is correct |
7 |
Correct |
3 ms |
348 KB |
Output is correct |
8 |
Correct |
3 ms |
604 KB |
Output is correct |
9 |
Correct |
4 ms |
596 KB |
Output is correct |
10 |
Runtime error |
80 ms |
21660 KB |
Execution killed with signal 6 |
11 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
440 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
3 ms |
600 KB |
Output is correct |
6 |
Correct |
3 ms |
348 KB |
Output is correct |
7 |
Correct |
3 ms |
604 KB |
Output is correct |
8 |
Correct |
4 ms |
596 KB |
Output is correct |
9 |
Runtime error |
80 ms |
21660 KB |
Execution killed with signal 6 |
10 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
432 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
440 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
3 ms |
600 KB |
Output is correct |
7 |
Correct |
3 ms |
348 KB |
Output is correct |
8 |
Correct |
3 ms |
604 KB |
Output is correct |
9 |
Correct |
4 ms |
596 KB |
Output is correct |
10 |
Runtime error |
80 ms |
21660 KB |
Execution killed with signal 6 |
11 |
Halted |
0 ms |
0 KB |
- |