# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
334822 | limabeans | 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 <bits/stdc++.h>
#include "swap.h"
using ll = long long;
const int maxn = 1e5 + 10;
int n;
vector<pair<ll,int>> g[maxn];
bool loop = false;
ll maxW = 0;
void dfs(int at, int p, int dep) {
if (dep==n) loop=true;
for (auto ed: g[at]) {
int to = ed.second;
if (to == p) continue;
dfs(to,at,dep+1);
}
}
void init(int N, int M, std::vector<int> U, std::vector<int> V, std::vector<int> W) {
n=N;
for (int i=0; i<M; i++) {
g[U[i]].push_back({W[i],V[i]});
g[V[i]].push_back({W[i],U[i]});
maxW=max(maxW,1ll*W[i]);
}
dfs(0,-1,0);
}
int getMinimumFuelCapacity(int X, int Y) {
if (loop) return maxW;
return -1;
}
/*
int main() {
init(5, 6, {0, 0, 1, 1, 1, 2}, {1, 2, 2, 3, 4, 3}, {4, 4, 1, 2, 10, 3});
cout<<getMinimumFuelCapacity(1, 2)<<endl;
cout<<getMinimumFuelCapacity(2, 4)<<endl;
cout<<getMinimumFuelCapacity(0, 1)<<endl;
return 0;
}
*/