#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(v));
}
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(M), V(M), W(M);
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
swap.cpp:52:1: warning: "/*" within comment [-Wcomment]
52 | /**/
|
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Incorrect |
108 ms |
8996 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |