#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;
bool cycle;
int maxW;
void init(int N, int M, vt<int> U, vt<int> V, vt<int> W)
{
vt<int> deg(N);
for(int i = 0; i < M; i++) deg[U[i]]++, deg[V[i]]++, maxW = max(maxW, W[i]);
cycle = 1;
for(int i = 0; i < N; i++) cycle = cycle & (deg[i] == 2);
}
int getMinimumFuelCapacity(int X, int Y)
{
return cycle ? maxW : -1;
}
/**
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
swap.cpp:50:1: warning: "/*" within comment [-Wcomment]
50 | /**/
|
# |
결과 |
실행 시간 |
메모리 |
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 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
304 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
31 ms |
4024 KB |
Output is correct |
10 |
Correct |
36 ms |
4856 KB |
Output is correct |
11 |
Correct |
34 ms |
4844 KB |
Output is correct |
12 |
Correct |
45 ms |
5044 KB |
Output is correct |
13 |
Correct |
39 ms |
5116 KB |
Output is correct |
14 |
Correct |
35 ms |
4392 KB |
Output is correct |
15 |
Correct |
96 ms |
8732 KB |
Output is correct |
16 |
Correct |
103 ms |
8676 KB |
Output is correct |
17 |
Correct |
105 ms |
9000 KB |
Output is correct |
18 |
Correct |
109 ms |
8944 KB |
Output is correct |
19 |
Correct |
60 ms |
5956 KB |
Output is correct |
20 |
Correct |
98 ms |
9664 KB |
Output is correct |
21 |
Correct |
102 ms |
9944 KB |
Output is correct |
22 |
Correct |
103 ms |
10156 KB |
Output is correct |
23 |
Correct |
104 ms |
10160 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Incorrect |
96 ms |
8124 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 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
304 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
# |
결과 |
실행 시간 |
메모리 |
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 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
304 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
31 ms |
4024 KB |
Output is correct |
10 |
Correct |
36 ms |
4856 KB |
Output is correct |
11 |
Correct |
34 ms |
4844 KB |
Output is correct |
12 |
Correct |
45 ms |
5044 KB |
Output is correct |
13 |
Correct |
39 ms |
5116 KB |
Output is correct |
14 |
Correct |
35 ms |
4392 KB |
Output is correct |
15 |
Correct |
96 ms |
8732 KB |
Output is correct |
16 |
Correct |
103 ms |
8676 KB |
Output is correct |
17 |
Correct |
105 ms |
9000 KB |
Output is correct |
18 |
Correct |
109 ms |
8944 KB |
Output is correct |
19 |
Incorrect |
96 ms |
8124 KB |
Output isn't correct |
20 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |