# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
735421 | keisuke6 | Swapping Cities (APIO20_swap) | C++17 | 0 ms | 0 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "swap.h"
#include <vector>
using namespace std;
int N,M;
vector<int> U,V,W,W_;
void init(int NN, int MM,
std::vector<int> UU, std::vector<int> VV, std::vector<int> WW) {
N = NN;
M = MM;
U = UU;
V = VV;
W = WW;
W_ = W;
for(int i=0;i<M;i++){
W[V[i]] = W_[i];
}
std::sort(W_.begin(),W_.end());
}
int getMinimumFuelCapacity(int X, int Y) {
if(N == 2) return -1;
if(X == 0){
if(W_[0] == W[Y-1]) return W_[1];
else return W_[0];
}
else{
int a = W[X-1];
int b = W[Y-1];
if(a > b) swap(a,b);
if(a == W_[0] && b == W_[1]) return W_[2];
else if(a == W_[0]) return W_[1];
else return W_[0];
}
}