#include "swap.h"
#include <bits/stdc++.h>
#include <vector>
using namespace std;
int ans;
vector<pair<int,int> >vp;
int fromzerotoX[100001];
int n , m;
int closedcircle=1;
vector<int>adj[100001];
void init(int N, int M, vector<int> U, vector<int> V, vector<int> W) {
n=N;
m=M;
for(int i = 0 ; i < V.size() ; i++)
{
adj[V[i]].push_back(U[i]);
adj[U[i]].push_back(V[i]);
fromzerotoX[V[i]]=W[i];
vp.push_back({W[i], V[i]});
}
ans=*max_element(W.begin() , W.end());
sort(vp.begin() , vp.end());
for(int i = 0 ; i < n ; i++)
{
if(adj[i].size()!=2)
{
closedcircle=0;
break;
}
}
}
int getMinimumFuelCapacity(int X, int Y){
if(m!=n-1)
{
if(closedcircle)
{
return ans;
}
return -1;
}
if(n<4)return -1;
int x=X , y=Y , out=0;
if(x>y)
{
swap(x,y);
}
if(x==0)
{
int c=0;
out=max(out , fromzerotoX[y]);
for(auto u :vp )
{
if(u.second!=y)
{
out=max(out , u.first);
c++;
}
if(c==2)
break;
}
return out;
}
out=max( fromzerotoX[x] , fromzerotoX[y]);
for(auto u :vp )
{
if(u.second!=y&&u.second!=x)
{
out=max(out , u.first);
break;
}
}
return out;
}
Compilation message
swap.cpp: In function 'void init(int, int, std::vector<int>, std::vector<int>, std::vector<int>)':
swap.cpp:14:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
14 | for(int i = 0 ; i < V.size() ; i++)
| ~~^~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2636 KB |
Output is correct |
2 |
Correct |
2 ms |
2636 KB |
Output is correct |
3 |
Correct |
2 ms |
2636 KB |
Output is correct |
4 |
Incorrect |
2 ms |
2636 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2636 KB |
Output is correct |
2 |
Correct |
2 ms |
2636 KB |
Output is correct |
3 |
Correct |
125 ms |
12304 KB |
Output is correct |
4 |
Correct |
133 ms |
12648 KB |
Output is correct |
5 |
Correct |
123 ms |
12680 KB |
Output is correct |
6 |
Correct |
122 ms |
12540 KB |
Output is correct |
7 |
Correct |
123 ms |
12684 KB |
Output is correct |
8 |
Correct |
118 ms |
12364 KB |
Output is correct |
9 |
Correct |
122 ms |
12676 KB |
Output is correct |
10 |
Correct |
121 ms |
12420 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2636 KB |
Output is correct |
2 |
Correct |
2 ms |
2636 KB |
Output is correct |
3 |
Correct |
2 ms |
2636 KB |
Output is correct |
4 |
Incorrect |
2 ms |
2636 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2636 KB |
Output is correct |
2 |
Correct |
2 ms |
2636 KB |
Output is correct |
3 |
Correct |
2 ms |
2636 KB |
Output is correct |
4 |
Incorrect |
2 ms |
2636 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2636 KB |
Output is correct |
2 |
Correct |
2 ms |
2636 KB |
Output is correct |
3 |
Correct |
2 ms |
2636 KB |
Output is correct |
4 |
Incorrect |
2 ms |
2636 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2636 KB |
Output is correct |
2 |
Correct |
2 ms |
2636 KB |
Output is correct |
3 |
Correct |
2 ms |
2636 KB |
Output is correct |
4 |
Incorrect |
2 ms |
2636 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |