#include <bits/stdc++.h>
// #include "grader_swap.cpp"
using namespace std;
#define lli long long int
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define test(x) cout << "Line(" << __LINE__ << ") " #x << ' ' << x << endl
#define printv(x) {\
for (auto i : x) cout << i << ' ';\
cout << endl;\
}
#define pii pair <int, int>
#define pll pair <lli, lli>
#define X first
#define Y second
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
template<typename A, typename B>
ostream& operator << (ostream& o, pair<A, B> a){
return o << a.X << ' ' << a.Y;
}
template<typename A, typename B>
istream& operator >> (istream& o, pair<A, B> &a){
return o >> a.X >> a.Y;
}
const int mod = 1e9 + 7, abc = 864197532, Doludu = 123, N = 100001, logN = 18, K = 40;
vector <pii> adj[N], out_of_tree[N];
int n, m;
void init(int _n, int _m, vector <int> u, vector <int> v, vector <int> w) {
n = _n, m = _m;
for (int i = 0; i < m; ++i) {
adj[u[i]].eb(v[i], w[i]);
adj[v[i]].eb(u[i], w[i]);
}
}
bool vis[N], cyc;
int cnt[N], mx;
void dfs(int v, int pa, int goal, int bound) {
vis[v] = true;
for (auto [u, w] : adj[v]) if (u != pa && w <= bound) {
if (vis[u]) cyc = true;
else cnt[v]++, cnt[u]++, mx = max({mx, cnt[v], cnt[u]}), dfs(u, v, goal, bound);
}
}
int getMinimumFuelCapacity(int u, int v) {
int l = 0, r = 1 << 30;
while (r - l > 1) {
int mid = l + r >> 1;
for (int i = 0; i < n; ++i) vis[i] = false, cnt[i] = 0;
cyc = false, mx = 0;
dfs(u, -1, v, mid);
if (vis[v] && (cyc || mx > 2)) r = mid;
else l = mid;
}
if (r == 1 << 30) r = -1;
return r;
}
/*
5 6
0 1 4
0 2 4
1 2 1
1 3 2
2 3 3
1 4 10
3
1 2
2 4
0 1
3 2
0 1 5
0 2 5
1
1 2
*/
Compilation message
swap.cpp: In function 'int getMinimumFuelCapacity(int, int)':
swap.cpp:55:21: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
55 | int mid = l + r >> 1;
| ~~^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
4940 KB |
Output is correct |
2 |
Correct |
3 ms |
4940 KB |
Output is correct |
3 |
Correct |
3 ms |
4940 KB |
Output is correct |
4 |
Correct |
5 ms |
5048 KB |
Output is correct |
5 |
Correct |
6 ms |
5068 KB |
Output is correct |
6 |
Correct |
7 ms |
5012 KB |
Output is correct |
7 |
Correct |
7 ms |
5152 KB |
Output is correct |
8 |
Correct |
9 ms |
5140 KB |
Output is correct |
9 |
Correct |
478 ms |
16520 KB |
Output is correct |
10 |
Correct |
1431 ms |
18268 KB |
Output is correct |
11 |
Correct |
1787 ms |
18504 KB |
Output is correct |
12 |
Correct |
1893 ms |
18512 KB |
Output is correct |
13 |
Correct |
1805 ms |
19272 KB |
Output is correct |
14 |
Execution timed out |
2093 ms |
16400 KB |
Time limit exceeded |
15 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
4940 KB |
Output is correct |
2 |
Correct |
3 ms |
4940 KB |
Output is correct |
3 |
Execution timed out |
2101 ms |
12416 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
4940 KB |
Output is correct |
2 |
Correct |
3 ms |
4940 KB |
Output is correct |
3 |
Correct |
3 ms |
4940 KB |
Output is correct |
4 |
Correct |
5 ms |
5048 KB |
Output is correct |
5 |
Correct |
6 ms |
5068 KB |
Output is correct |
6 |
Correct |
7 ms |
5012 KB |
Output is correct |
7 |
Correct |
7 ms |
5152 KB |
Output is correct |
8 |
Correct |
9 ms |
5140 KB |
Output is correct |
9 |
Correct |
3 ms |
4996 KB |
Output is correct |
10 |
Correct |
5 ms |
5068 KB |
Output is correct |
11 |
Correct |
6 ms |
5068 KB |
Output is correct |
12 |
Correct |
7 ms |
5068 KB |
Output is correct |
13 |
Correct |
6 ms |
5008 KB |
Output is correct |
14 |
Correct |
6 ms |
5068 KB |
Output is correct |
15 |
Correct |
6 ms |
5068 KB |
Output is correct |
16 |
Correct |
7 ms |
5068 KB |
Output is correct |
17 |
Correct |
7 ms |
5136 KB |
Output is correct |
18 |
Correct |
6 ms |
5068 KB |
Output is correct |
19 |
Correct |
6 ms |
5016 KB |
Output is correct |
20 |
Correct |
6 ms |
5012 KB |
Output is correct |
21 |
Correct |
8 ms |
5008 KB |
Output is correct |
22 |
Correct |
6 ms |
5068 KB |
Output is correct |
23 |
Correct |
5 ms |
5068 KB |
Output is correct |
24 |
Correct |
6 ms |
5068 KB |
Output is correct |
25 |
Correct |
6 ms |
5140 KB |
Output is correct |
26 |
Correct |
9 ms |
5196 KB |
Output is correct |
27 |
Correct |
6 ms |
5136 KB |
Output is correct |
28 |
Correct |
7 ms |
5068 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
4996 KB |
Output is correct |
2 |
Correct |
3 ms |
4940 KB |
Output is correct |
3 |
Correct |
3 ms |
4940 KB |
Output is correct |
4 |
Correct |
3 ms |
4940 KB |
Output is correct |
5 |
Correct |
5 ms |
5048 KB |
Output is correct |
6 |
Correct |
6 ms |
5068 KB |
Output is correct |
7 |
Correct |
7 ms |
5012 KB |
Output is correct |
8 |
Correct |
7 ms |
5152 KB |
Output is correct |
9 |
Correct |
9 ms |
5140 KB |
Output is correct |
10 |
Correct |
478 ms |
16520 KB |
Output is correct |
11 |
Correct |
1431 ms |
18268 KB |
Output is correct |
12 |
Correct |
1787 ms |
18504 KB |
Output is correct |
13 |
Correct |
1893 ms |
18512 KB |
Output is correct |
14 |
Correct |
1805 ms |
19272 KB |
Output is correct |
15 |
Correct |
5 ms |
5068 KB |
Output is correct |
16 |
Correct |
6 ms |
5068 KB |
Output is correct |
17 |
Correct |
7 ms |
5068 KB |
Output is correct |
18 |
Correct |
6 ms |
5008 KB |
Output is correct |
19 |
Correct |
6 ms |
5068 KB |
Output is correct |
20 |
Correct |
6 ms |
5068 KB |
Output is correct |
21 |
Correct |
7 ms |
5068 KB |
Output is correct |
22 |
Correct |
7 ms |
5136 KB |
Output is correct |
23 |
Correct |
6 ms |
5068 KB |
Output is correct |
24 |
Correct |
6 ms |
5016 KB |
Output is correct |
25 |
Correct |
6 ms |
5012 KB |
Output is correct |
26 |
Correct |
8 ms |
5008 KB |
Output is correct |
27 |
Correct |
6 ms |
5068 KB |
Output is correct |
28 |
Correct |
5 ms |
5068 KB |
Output is correct |
29 |
Correct |
6 ms |
5068 KB |
Output is correct |
30 |
Correct |
6 ms |
5140 KB |
Output is correct |
31 |
Correct |
9 ms |
5196 KB |
Output is correct |
32 |
Correct |
6 ms |
5136 KB |
Output is correct |
33 |
Correct |
7 ms |
5068 KB |
Output is correct |
34 |
Correct |
20 ms |
6092 KB |
Output is correct |
35 |
Correct |
1360 ms |
17424 KB |
Output is correct |
36 |
Correct |
1218 ms |
14876 KB |
Output is correct |
37 |
Correct |
1091 ms |
12700 KB |
Output is correct |
38 |
Correct |
1155 ms |
12100 KB |
Output is correct |
39 |
Correct |
1010 ms |
12152 KB |
Output is correct |
40 |
Correct |
880 ms |
11672 KB |
Output is correct |
41 |
Correct |
1102 ms |
15876 KB |
Output is correct |
42 |
Correct |
1630 ms |
16488 KB |
Output is correct |
43 |
Correct |
1271 ms |
18728 KB |
Output is correct |
44 |
Correct |
660 ms |
12996 KB |
Output is correct |
45 |
Correct |
1084 ms |
17876 KB |
Output is correct |
46 |
Correct |
1504 ms |
16936 KB |
Output is correct |
47 |
Correct |
1223 ms |
12180 KB |
Output is correct |
48 |
Correct |
1060 ms |
13084 KB |
Output is correct |
49 |
Correct |
122 ms |
16328 KB |
Output is correct |
50 |
Correct |
132 ms |
13444 KB |
Output is correct |
51 |
Correct |
549 ms |
16248 KB |
Output is correct |
52 |
Correct |
763 ms |
20136 KB |
Output is correct |
53 |
Correct |
680 ms |
19444 KB |
Output is correct |
54 |
Execution timed out |
2095 ms |
23180 KB |
Time limit exceeded |
55 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
4940 KB |
Output is correct |
2 |
Correct |
3 ms |
4940 KB |
Output is correct |
3 |
Correct |
3 ms |
4940 KB |
Output is correct |
4 |
Correct |
5 ms |
5048 KB |
Output is correct |
5 |
Correct |
6 ms |
5068 KB |
Output is correct |
6 |
Correct |
7 ms |
5012 KB |
Output is correct |
7 |
Correct |
7 ms |
5152 KB |
Output is correct |
8 |
Correct |
9 ms |
5140 KB |
Output is correct |
9 |
Correct |
478 ms |
16520 KB |
Output is correct |
10 |
Correct |
1431 ms |
18268 KB |
Output is correct |
11 |
Correct |
1787 ms |
18504 KB |
Output is correct |
12 |
Correct |
1893 ms |
18512 KB |
Output is correct |
13 |
Correct |
1805 ms |
19272 KB |
Output is correct |
14 |
Execution timed out |
2093 ms |
16400 KB |
Time limit exceeded |
15 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
4996 KB |
Output is correct |
2 |
Correct |
3 ms |
4940 KB |
Output is correct |
3 |
Correct |
3 ms |
4940 KB |
Output is correct |
4 |
Correct |
3 ms |
4940 KB |
Output is correct |
5 |
Correct |
5 ms |
5048 KB |
Output is correct |
6 |
Correct |
6 ms |
5068 KB |
Output is correct |
7 |
Correct |
7 ms |
5012 KB |
Output is correct |
8 |
Correct |
7 ms |
5152 KB |
Output is correct |
9 |
Correct |
9 ms |
5140 KB |
Output is correct |
10 |
Correct |
478 ms |
16520 KB |
Output is correct |
11 |
Correct |
1431 ms |
18268 KB |
Output is correct |
12 |
Correct |
1787 ms |
18504 KB |
Output is correct |
13 |
Correct |
1893 ms |
18512 KB |
Output is correct |
14 |
Correct |
1805 ms |
19272 KB |
Output is correct |
15 |
Execution timed out |
2093 ms |
16400 KB |
Time limit exceeded |
16 |
Halted |
0 ms |
0 KB |
- |