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 <bits/stdc++.h>
using namespace std;
int n, m;
vector<vector<pair<int, int>>> adj;
namespace subtask1 {
bool cycle = false;
int gas = 0;
vector<bool> visited;
void dfs(int s, int v)
{
if (visited[s]) return;
visited[s] = true;
for (auto u: adj[s])
{
if (visited[u.first] && u.first != v) cycle = true;
gas = max(gas, u.second);
dfs(u.first, s);
}
}
}
namespace subtask2 {
bool nodes = false;
bool variation = false;
bool execution = false;
vector<pair<int, int>> edge;
int gas = 0;
}
void init(int n1, int m1, vector<int> v, vector<int> u, vector<int> w) {
n = n1;
m = m1;
adj.resize(n);
for (int i=0; i<m; i++)
{
adj[v[i]].push_back({u[i], w[i]});
adj[u[i]].push_back({v[i], w[i]});
}
//subtask1
subtask1::visited.resize(n);
//subtask2
if (m == (n-1)) {subtask2::nodes = true;}
for (auto s: v) {if (s != 0) {subtask2::variation = true;}}
subtask2::execution = (subtask2::nodes && !(subtask2::variation));
if (subtask2::execution)
{
for (auto u: adj[0])
{
subtask2::edge.push_back({u.second, u.first});
}
sort(subtask2::edge.begin(), subtask2::edge.end());
subtask2::edge.erase(subtask2::edge.begin()+3, subtask2::edge.end());
}
}
int getMinimumFuelCapacity(int x, int y){
if (subtask2::execution)
{
if (n < 4) return -1;
subtask2::gas = max(adj[x][0].second, adj[y][0].second);
for (auto &u: subtask2::edge)
{
if (u.second != x && u.second != y) {return max(u.first, subtask2::gas);}
}
}
else
{
subtask1::dfs(1, 0);
return (subtask1::cycle ? subtask1::gas : -1);
}
}
Compilation message (stderr)
swap.cpp: In function 'int getMinimumFuelCapacity(int, int)':
swap.cpp:76:1: warning: control reaches end of non-void function [-Wreturn-type]
76 | }
| ^
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |