이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <swap.h>
#include <bits/stdc++.h>
using namespace std;
int n, m;
vector<vector<pair<int, int>>> adj;
vector<bool> visited;
bool cycle = false;
int gas = 0;
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;
}
void init(int n1, int m1, vector<int> v, vector<int> u, vector<int> w) {
n = n1;
m = m1;
adj.resize(n+1);
visited.resize(n+1);
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]});
}
//confirmation for subtask2
if (m1 == (n1-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;
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, gas);}
}
}
dfs(1, 0);
return (cycle ? gas : -1);
}
# | 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... |