#include "swap.h"
#include <vector>
#include<bits/stdc++.h>
using namespace std;
#define L(i, j, k) for (int i = (j); i <= k; i++)
#define R(i, j, k) for (int i = (j); i >= k; i--)
const int nax = 100050;
int N, M, to[nax];
vector<pair<int, int>> G[nax];
pair<int, int> T[nax];
void init(int _N, int _M, std::vector<int> _U, std::vector<int> _V, std::vector<int> _W) {
N = _N; M = _M;
L(i, 0, M - 1){
T[i] = make_pair(_W[i], _V[i]);
to[_V[i]] = _W[i];
}
sort(T, T + M);
}
int getMinimumFuelCapacity(int X, int Y) {
if (N <= 3) return -1;
if (X == 0) {
int count = 0, ans = to[Y];
L(i, 0, 2) {
// 1: we want to find 0 -> A (that is not Y)
// 2: Y -> 0 -> B,
// 1: A -> 0 -> Y
// 2: B -> 0
// we need at most 2 nodes that is not Y
if (T[i].second == Y) continue;
count++;
ans = max(ans, T[i].first);
if (count >= 2) break;
}
return ans;
}
else {
// 1: X -> 0 -> A
// 2: Y -> 0 -> X
// 1: A -> 0 -> Y
// we need at most one node that is not X and not Y
L(i, 0, 2) {
if (T[i].second != X && T[i].second != Y) {
return max({T[i].first, to[X], to[Y]});
}
}
}
}
Compilation message
swap.cpp: In function 'int getMinimumFuelCapacity(int, int)':
swap.cpp:52:1: warning: control reaches end of non-void function [-Wreturn-type]
52 | }
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
3164 KB |
Output is correct |
2 |
Correct |
1 ms |
3164 KB |
Output is correct |
3 |
Correct |
1 ms |
3164 KB |
Output is correct |
4 |
Incorrect |
1 ms |
3164 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
3164 KB |
Output is correct |
2 |
Correct |
1 ms |
3164 KB |
Output is correct |
3 |
Correct |
66 ms |
8976 KB |
Output is correct |
4 |
Correct |
68 ms |
8888 KB |
Output is correct |
5 |
Correct |
70 ms |
9196 KB |
Output is correct |
6 |
Correct |
67 ms |
9040 KB |
Output is correct |
7 |
Correct |
72 ms |
9168 KB |
Output is correct |
8 |
Correct |
70 ms |
9216 KB |
Output is correct |
9 |
Correct |
68 ms |
9168 KB |
Output is correct |
10 |
Correct |
68 ms |
9032 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
3164 KB |
Output is correct |
2 |
Correct |
1 ms |
3164 KB |
Output is correct |
3 |
Correct |
1 ms |
3164 KB |
Output is correct |
4 |
Incorrect |
1 ms |
3164 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
3164 KB |
Output is correct |
2 |
Correct |
1 ms |
3164 KB |
Output is correct |
3 |
Correct |
1 ms |
3164 KB |
Output is correct |
4 |
Incorrect |
1 ms |
3164 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
3164 KB |
Output is correct |
2 |
Correct |
1 ms |
3164 KB |
Output is correct |
3 |
Correct |
1 ms |
3164 KB |
Output is correct |
4 |
Incorrect |
1 ms |
3164 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
3164 KB |
Output is correct |
2 |
Correct |
1 ms |
3164 KB |
Output is correct |
3 |
Correct |
1 ms |
3164 KB |
Output is correct |
4 |
Incorrect |
1 ms |
3164 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |