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>
#define ll long long
#define ld long double
#define vt vector
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define sz(x) (x).size()
#pragma GCC optimize ("O3")
#pragma GCC optimize ("O2")
//#define endl '\n'
//#define int ll
using namespace std;
vt<pair<int, int>> v;
vt<int> weight;
void init(int N, int M, vt<int> U, vt<int> V, vt<int> W)
{
weight.resize(N);
for(int i = 0; i < M; i++) v.pb({W[i], V[i]}), weight[V[i]] = W[i];
sort(all(weight));
}
int getMinimumFuelCapacity(int X, int Y)
{
if (sz(v) == 2) return -1;
if (min(X, Y) == min(v[0].second, v[1].second) &&
max(X, Y) == max(v[0].second, v[1].second)) return v[2].second;
return max(weight[X], weight[Y]);
}
/**
main()
{
ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
freopen("input.txt", "r", stdin);
int N, M, Q;
cin >> N >> M;
vt<int> U, V, W;
for(int i = 0; i < M; i++) cin >> U[i] >> V[i] >> W[i];
init(N, M, U, V, W);
cin >> Q;
while(Q--)
{
int X, Y;
cin >> X >> Y;
cout << getMinimumFuelCapacity(X, Y) << endl;
}
}
/**/
Compilation message (stderr)
swap.cpp:52:1: warning: "/*" within comment [-Wcomment]
52 | /**/
|
# | 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... |