#include <bits/stdc++.h>
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
using namespace std;
const int MAX = 1e5+5;
int n, m, used[MAX];
vector <pair <int, int>> g[MAX];
void init (int N, int M, vector <int> U, vector <int> V, vector <int> W) {
n = N;
m = M;
int inf = 0;
for (int i = 0; i < M; i ++) {
g[U[i]].push_back({V[i], W[i]});
g[V[i]].push_back({U[i], W[i]});
}
}
void dfs (int v, int p, int k, int& flag){
used[v] = 1;
int deg = 0;
for (auto i: g[v]) {
if (i.second <= k and i.first != p and used[i.first] == 1)
flag = 1;
if (i.second <= k and !used[i.first])
dfs(i.first, v, k, flag);
if (i.second <= k)
deg ++;
}
if (deg >= 3) flag = 1;
used[v] = 2;
}
bool isPossible (int a, int b, int k) {
memset(used, 0, sizeof(used));
int flag = 0;
dfs(a, -1, k, flag);
if (flag and used[b]) return true;
else return false;
}
int getMinimumFuelCapacity (int X, int Y) {
int l = 1, r = 1e9, best = -1;
while (l <= r) {
int mid = (l + r) / 2;
if (isPossible(X, Y, mid)) {
best = mid;
r = mid - 1;
}
else {
l = mid + 1;
}
}
return best;
}
Compilation message
swap.cpp:4: warning: ignoring '#pragma GCC optimization' [-Wunknown-pragmas]
4 | #pragma GCC optimization ("O3")
|
swap.cpp:5: warning: ignoring '#pragma GCC optimization' [-Wunknown-pragmas]
5 | #pragma GCC optimization ("unroll-loops")
|
swap.cpp: In function 'void init(int, int, std::vector<int>, std::vector<int>, std::vector<int>)':
swap.cpp:17:9: warning: unused variable 'inf' [-Wunused-variable]
17 | int inf = 0;
| ^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
3020 KB |
Output is correct |
2 |
Correct |
3 ms |
3020 KB |
Output is correct |
3 |
Correct |
4 ms |
3020 KB |
Output is correct |
4 |
Correct |
6 ms |
3020 KB |
Output is correct |
5 |
Correct |
6 ms |
3020 KB |
Output is correct |
6 |
Correct |
7 ms |
3020 KB |
Output is correct |
7 |
Correct |
7 ms |
3148 KB |
Output is correct |
8 |
Correct |
8 ms |
3148 KB |
Output is correct |
9 |
Correct |
326 ms |
12440 KB |
Output is correct |
10 |
Correct |
1025 ms |
13924 KB |
Output is correct |
11 |
Correct |
1624 ms |
14160 KB |
Output is correct |
12 |
Correct |
1438 ms |
13936 KB |
Output is correct |
13 |
Execution timed out |
2062 ms |
14764 KB |
Time limit exceeded |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
3020 KB |
Output is correct |
2 |
Correct |
3 ms |
3020 KB |
Output is correct |
3 |
Execution timed out |
2076 ms |
10060 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
3020 KB |
Output is correct |
2 |
Correct |
3 ms |
3020 KB |
Output is correct |
3 |
Correct |
4 ms |
3020 KB |
Output is correct |
4 |
Correct |
6 ms |
3020 KB |
Output is correct |
5 |
Correct |
6 ms |
3020 KB |
Output is correct |
6 |
Correct |
7 ms |
3020 KB |
Output is correct |
7 |
Correct |
7 ms |
3148 KB |
Output is correct |
8 |
Correct |
8 ms |
3148 KB |
Output is correct |
9 |
Correct |
4 ms |
3020 KB |
Output is correct |
10 |
Correct |
9 ms |
3020 KB |
Output is correct |
11 |
Correct |
8 ms |
3148 KB |
Output is correct |
12 |
Correct |
8 ms |
3048 KB |
Output is correct |
13 |
Correct |
7 ms |
3036 KB |
Output is correct |
14 |
Correct |
6 ms |
3048 KB |
Output is correct |
15 |
Correct |
7 ms |
3128 KB |
Output is correct |
16 |
Correct |
8 ms |
3148 KB |
Output is correct |
17 |
Correct |
8 ms |
3148 KB |
Output is correct |
18 |
Correct |
7 ms |
3020 KB |
Output is correct |
19 |
Correct |
6 ms |
3048 KB |
Output is correct |
20 |
Correct |
8 ms |
3160 KB |
Output is correct |
21 |
Correct |
8 ms |
3020 KB |
Output is correct |
22 |
Correct |
7 ms |
3148 KB |
Output is correct |
23 |
Correct |
6 ms |
3020 KB |
Output is correct |
24 |
Correct |
7 ms |
3148 KB |
Output is correct |
25 |
Correct |
8 ms |
3148 KB |
Output is correct |
26 |
Correct |
11 ms |
3148 KB |
Output is correct |
27 |
Correct |
7 ms |
3160 KB |
Output is correct |
28 |
Correct |
8 ms |
3176 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
3020 KB |
Output is correct |
2 |
Correct |
3 ms |
3020 KB |
Output is correct |
3 |
Correct |
3 ms |
3020 KB |
Output is correct |
4 |
Correct |
4 ms |
3020 KB |
Output is correct |
5 |
Correct |
6 ms |
3020 KB |
Output is correct |
6 |
Correct |
6 ms |
3020 KB |
Output is correct |
7 |
Correct |
7 ms |
3020 KB |
Output is correct |
8 |
Correct |
7 ms |
3148 KB |
Output is correct |
9 |
Correct |
8 ms |
3148 KB |
Output is correct |
10 |
Correct |
326 ms |
12440 KB |
Output is correct |
11 |
Correct |
1025 ms |
13924 KB |
Output is correct |
12 |
Correct |
1624 ms |
14160 KB |
Output is correct |
13 |
Correct |
1438 ms |
13936 KB |
Output is correct |
14 |
Execution timed out |
2062 ms |
14764 KB |
Time limit exceeded |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
3020 KB |
Output is correct |
2 |
Correct |
3 ms |
3020 KB |
Output is correct |
3 |
Correct |
4 ms |
3020 KB |
Output is correct |
4 |
Correct |
6 ms |
3020 KB |
Output is correct |
5 |
Correct |
6 ms |
3020 KB |
Output is correct |
6 |
Correct |
7 ms |
3020 KB |
Output is correct |
7 |
Correct |
7 ms |
3148 KB |
Output is correct |
8 |
Correct |
8 ms |
3148 KB |
Output is correct |
9 |
Correct |
326 ms |
12440 KB |
Output is correct |
10 |
Correct |
1025 ms |
13924 KB |
Output is correct |
11 |
Correct |
1624 ms |
14160 KB |
Output is correct |
12 |
Correct |
1438 ms |
13936 KB |
Output is correct |
13 |
Execution timed out |
2062 ms |
14764 KB |
Time limit exceeded |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
3020 KB |
Output is correct |
2 |
Correct |
3 ms |
3020 KB |
Output is correct |
3 |
Correct |
3 ms |
3020 KB |
Output is correct |
4 |
Correct |
4 ms |
3020 KB |
Output is correct |
5 |
Correct |
6 ms |
3020 KB |
Output is correct |
6 |
Correct |
6 ms |
3020 KB |
Output is correct |
7 |
Correct |
7 ms |
3020 KB |
Output is correct |
8 |
Correct |
7 ms |
3148 KB |
Output is correct |
9 |
Correct |
8 ms |
3148 KB |
Output is correct |
10 |
Correct |
326 ms |
12440 KB |
Output is correct |
11 |
Correct |
1025 ms |
13924 KB |
Output is correct |
12 |
Correct |
1624 ms |
14160 KB |
Output is correct |
13 |
Correct |
1438 ms |
13936 KB |
Output is correct |
14 |
Execution timed out |
2062 ms |
14764 KB |
Time limit exceeded |