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;
typedef long long ll;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
#define precision(n) fixed << setprecision(n)
#define pb push_back
#define ub upper_bound
#define lb lower_bound
#define mp make_pair
#define eps (double)1e-9
#define PI 2*acos(0.0)
#define endl "\n"
#define sz(v) int((v).size())
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define do_not_disturb ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define OK cout << "OK" << endl;
const int N = 1e5+7;
vector <pii> graph[N];
int mx;
multiset <int> st;
bool less3 = 1, less2 = 0;
void init(int n, int m, vector<int> U, vector<int> V, vector<int> W) {
for (int i = 0; i < m; i++) {
graph[U[i]].pb(mp(V[i], W[i]));
graph[V[i]].pb(mp(U[i], W[i]));
}
for (int i = 0; i < n; i++) {
sort(all(graph[i]));
if (sz(graph[i]) > 2) less3 = 0;
}
for (auto to : W) st.insert(to);
if (less3) {
for (int i = 0; i < n; i++) {
if (sz(graph[i]) == 1) less2 = 1;
}
if (!less2) mx = *max_element(all(W));
}
}
int getMinimumFuelCapacity(int X, int Y) {
if (less3) {
if (less2) return -1;
return mx;
}
else {
if (!X || !Y) {
int a = (*lb(all(graph[0]), mp(max(X, Y), 0))).second;
st.erase(st.find(a));
int b = *st.begin();
st.erase(st.begin());
int c = *st.begin();
st.insert(a); st.insert(b);
return max({a, b, c});
}
else {
int a = (*lb(all(graph[0]), mp(X, 0))).second, b = (*lb(all(graph[0]), mp(Y, 0))).second;
st.erase(st.find(a));
st.erase(st.find(b));
int c = *st.begin();
st.insert(a);
st.insert(b);
return max(c, max(a, b));
}
}
}
# | 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... |