// CF template, version 3.0
#include <bits/stdc++.h>
using namespace std;
#define improvePerformance ios_base::sync_with_stdio(false); cin.tie(0)
#define getTest int t; cin >> t
#define eachTest for (int _var=0;_var<t;_var++)
#define get(name) int (name); cin >> (name)
#define out(o) cout << (o)
#define getList(cnt, name) vector<int> (name); for (int _=0;_<(cnt);_++) { get(a); (name).push_back(a); }
#define sortl(name) sort((name).begin(), (name).end())
#define rev(name) reverse((name).begin(), (name).end())
#define forto(name, var) for (int (var) = 0; (var) < (name); (var)++)
#define decision(b) if (b){out("YES");}else{out("NO");}
//#define int long long int
template <typename T, typename I>
struct segtree {
int n;
vector<T> tree;
vector<I> initial;
T id;
segtree(int i_n, vector<I> i_initial, T i_id): n(i_n), initial(i_initial), id(i_id) {
tree.resize(4 * n);
}
T conquer(T left, T right) {
// write your conquer function
}
T value(I inp) {
// write your value function
}
void build(int v, int l, int r) {
if (l == r) tree[v] = value(initial[l]);
else {
int middle = (l + r) / 2;
build(2 * v, l, middle);
build(2 * v + 1, middle + 1, r);
tree[v] = conquer(tree[2 * v], tree[2 * v + 1]);
}
}
void upd(int v, int l, int r, int i, I x) {
if (l == r) tree[v] = value(x);
else {
int middle = (l + r) / 2;
if (middle >= i) upd(2 * v, l, middle, i, x);
else upd(2 * v + 1, middle + 1, r, i, x);
tree[v] = conquer(tree[2 * v], tree[2 * v + 1]);
}
}
T query(int v, int l, int r, int ql, int qr) {
if (ql <= l && r <= qr) return tree[v];
else if (r < ql || qr < l) return id;
int middle = (l + r) / 2;
T left = query(2 * v, l, middle, ql, qr);
T right = query(2 * v + 1, middle + 1, r, ql, qr);
return conquer(left, right);
}
};
// vector<int>
vector<int> parent;
vector<vector<int>> comps;
vector<int> deg;
vector<int> maxdeg;
vector<int> edges;
vector<bool> marked;
vector<int> nonline;
vector<vector<pair<int, int>>> merges;
int find(int v) {
if (v == parent[v]) return v;
return parent[v] = find(parent[v]);
}
void unite(int u, int v, int val) {
int a = find(u);
int b = find(v);
deg[u]++;
deg[v]++;
if (a == b) {
maxdeg[a] = max({maxdeg[a], deg[u], deg[v]});
edges[a]++;
if (!marked[a] && (maxdeg[a] >= 3 || edges[a] == comps[a].size())) {
marked[a] = true;
for (int node: comps[a]) nonline[node] = min(nonline[node], val);
}
} else {
if (comps[a].size() > comps[b].size()) swap(a, b);
maxdeg[b] = max({maxdeg[b], deg[u], deg[v]});
if (marked[a] && !marked[b]) for (int node: comps[b]) nonline[node] = min(nonline[node], val);
while (!comps[a].empty()) {
int node = comps[a].back();
comps[a].pop_back();
comps[b].push_back(node);
merges[node].push_back({val, b});
maxdeg[b] = max(maxdeg[b], deg[node]);
if (marked[b] && !marked[a]) nonline[node] = min(nonline[node], val);
}
if (!marked[a] && !marked[b] && (maxdeg[b] >= 3 || edges[b] == comps[b].size())) {
marked[b] = true;
for (int node: comps[b]) nonline[node] = min(nonline[node], val);
}
parent[a] = b;
edges[b] += edges[a] + 1;
}
}
void init(int N, int M, vector<int> U, vector<int> V, vector<int> W) {
forto(N, i) {
parent.push_back(i);
vector<int> here1;
here1.push_back(i);
comps.push_back(here1);
deg.push_back(0);
maxdeg.push_back(0);
edges.push_back(0);
marked.push_back(false);
nonline.push_back(1e9 + 5);
vector<pair<int, int>> here2;
merges.push_back(here2);
}
vector<array<int, 3>> sorted;
forto(M, i) sorted.push_back({W[i], U[i], V[i]});
sortl(sorted);
forto(M, i) {
int w = sorted[i][0];
int u = sorted[i][1];
int v = sorted[i][2];
unite(u, v, w);
}
}
int getMinimumFuelCapacity(int X, int Y) {
int one = nonline[X];
if (one == 1e9 + 5) return -1;
vector<array<int, 3>> events;
for (pair<int, int> event: merges[X]) events.push_back({event.first, event.second, 0});
for (pair<int, int> event: merges[Y]) events.push_back({event.first, event.second, 1});
sortl(events);
int parX = X;
int parY = Y;
int two;
for (array<int, 3> event: events) {
if (event[2] == 0) parX = event[1];
else parY = event[1];
if (parX == parY) {
two = event[0];
break;
}
}
return max(one, two);
}
Compilation message
swap.cpp: In function 'void unite(int, int, int)':
swap.cpp:93:55: warning: comparison of integer expressions of different signedness: '__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type' {aka 'int'} and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
93 | if (!marked[a] && (maxdeg[a] >= 3 || edges[a] == comps[a].size())) {
swap.cpp:109:69: warning: comparison of integer expressions of different signedness: '__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type' {aka 'int'} and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
109 | if (!marked[a] && !marked[b] && (maxdeg[b] >= 3 || edges[b] == comps[b].size())) {
swap.cpp: In function 'void init(int, int, std::vector<int>, std::vector<int>, std::vector<int>)':
swap.cpp:15:35: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
15 | #define forto(name, var) for (int (var) = 0; (var) < (name); (var)++)
| ^
swap.cpp:119:5: note: in expansion of macro 'forto'
119 | forto(N, i) {
| ^~~~~
swap.cpp:15:35: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
15 | #define forto(name, var) for (int (var) = 0; (var) < (name); (var)++)
| ^
swap.cpp:141:5: note: in expansion of macro 'forto'
141 | forto(M, i) sorted.push_back({W[i], U[i], V[i]});
| ^~~~~
swap.cpp:15:35: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
15 | #define forto(name, var) for (int (var) = 0; (var) < (name); (var)++)
| ^
swap.cpp:143:5: note: in expansion of macro 'forto'
143 | forto(M, i) {
| ^~~~~
swap.cpp: In function 'int getMinimumFuelCapacity(int, int)':
swap.cpp:160:9: warning: 'two' may be used uninitialized in this function [-Wmaybe-uninitialized]
160 | int two;
| ^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
604 KB |
Output is correct |
6 |
Correct |
0 ms |
604 KB |
Output is correct |
7 |
Correct |
1 ms |
604 KB |
Output is correct |
8 |
Correct |
1 ms |
440 KB |
Output is correct |
9 |
Correct |
63 ms |
21676 KB |
Output is correct |
10 |
Correct |
73 ms |
25008 KB |
Output is correct |
11 |
Correct |
75 ms |
24752 KB |
Output is correct |
12 |
Correct |
77 ms |
26032 KB |
Output is correct |
13 |
Correct |
54 ms |
18096 KB |
Output is correct |
14 |
Correct |
59 ms |
22064 KB |
Output is correct |
15 |
Correct |
102 ms |
27308 KB |
Output is correct |
16 |
Correct |
98 ms |
26544 KB |
Output is correct |
17 |
Correct |
104 ms |
27568 KB |
Output is correct |
18 |
Correct |
82 ms |
19628 KB |
Output is correct |
19 |
Correct |
65 ms |
7628 KB |
Output is correct |
20 |
Correct |
153 ms |
27696 KB |
Output is correct |
21 |
Correct |
152 ms |
27188 KB |
Output is correct |
22 |
Correct |
175 ms |
28696 KB |
Output is correct |
23 |
Correct |
119 ms |
20276 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
84 ms |
19024 KB |
Output is correct |
4 |
Correct |
93 ms |
23576 KB |
Output is correct |
5 |
Correct |
90 ms |
23368 KB |
Output is correct |
6 |
Correct |
86 ms |
22556 KB |
Output is correct |
7 |
Correct |
91 ms |
23344 KB |
Output is correct |
8 |
Correct |
89 ms |
21688 KB |
Output is correct |
9 |
Correct |
90 ms |
22820 KB |
Output is correct |
10 |
Correct |
85 ms |
22380 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
604 KB |
Output is correct |
6 |
Correct |
0 ms |
604 KB |
Output is correct |
7 |
Correct |
1 ms |
604 KB |
Output is correct |
8 |
Correct |
1 ms |
440 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
604 KB |
Output is correct |
11 |
Correct |
1 ms |
604 KB |
Output is correct |
12 |
Correct |
1 ms |
604 KB |
Output is correct |
13 |
Correct |
0 ms |
604 KB |
Output is correct |
14 |
Correct |
1 ms |
604 KB |
Output is correct |
15 |
Correct |
1 ms |
604 KB |
Output is correct |
16 |
Correct |
0 ms |
604 KB |
Output is correct |
17 |
Correct |
1 ms |
604 KB |
Output is correct |
18 |
Correct |
1 ms |
604 KB |
Output is correct |
19 |
Correct |
1 ms |
604 KB |
Output is correct |
20 |
Correct |
0 ms |
604 KB |
Output is correct |
21 |
Correct |
1 ms |
448 KB |
Output is correct |
22 |
Correct |
1 ms |
348 KB |
Output is correct |
23 |
Correct |
1 ms |
604 KB |
Output is correct |
24 |
Correct |
1 ms |
600 KB |
Output is correct |
25 |
Correct |
1 ms |
604 KB |
Output is correct |
26 |
Correct |
1 ms |
604 KB |
Output is correct |
27 |
Correct |
0 ms |
604 KB |
Output is correct |
28 |
Correct |
1 ms |
604 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
604 KB |
Output is correct |
7 |
Correct |
0 ms |
604 KB |
Output is correct |
8 |
Correct |
1 ms |
604 KB |
Output is correct |
9 |
Correct |
1 ms |
440 KB |
Output is correct |
10 |
Correct |
63 ms |
21676 KB |
Output is correct |
11 |
Correct |
73 ms |
25008 KB |
Output is correct |
12 |
Correct |
75 ms |
24752 KB |
Output is correct |
13 |
Correct |
77 ms |
26032 KB |
Output is correct |
14 |
Correct |
54 ms |
18096 KB |
Output is correct |
15 |
Correct |
1 ms |
604 KB |
Output is correct |
16 |
Correct |
1 ms |
604 KB |
Output is correct |
17 |
Correct |
1 ms |
604 KB |
Output is correct |
18 |
Correct |
0 ms |
604 KB |
Output is correct |
19 |
Correct |
1 ms |
604 KB |
Output is correct |
20 |
Correct |
1 ms |
604 KB |
Output is correct |
21 |
Correct |
0 ms |
604 KB |
Output is correct |
22 |
Correct |
1 ms |
604 KB |
Output is correct |
23 |
Correct |
1 ms |
604 KB |
Output is correct |
24 |
Correct |
1 ms |
604 KB |
Output is correct |
25 |
Correct |
0 ms |
604 KB |
Output is correct |
26 |
Correct |
1 ms |
448 KB |
Output is correct |
27 |
Correct |
1 ms |
348 KB |
Output is correct |
28 |
Correct |
1 ms |
604 KB |
Output is correct |
29 |
Correct |
1 ms |
600 KB |
Output is correct |
30 |
Correct |
1 ms |
604 KB |
Output is correct |
31 |
Correct |
1 ms |
604 KB |
Output is correct |
32 |
Correct |
0 ms |
604 KB |
Output is correct |
33 |
Correct |
1 ms |
604 KB |
Output is correct |
34 |
Correct |
10 ms |
3540 KB |
Output is correct |
35 |
Correct |
80 ms |
27500 KB |
Output is correct |
36 |
Correct |
73 ms |
27680 KB |
Output is correct |
37 |
Correct |
73 ms |
26800 KB |
Output is correct |
38 |
Correct |
69 ms |
26120 KB |
Output is correct |
39 |
Correct |
69 ms |
25008 KB |
Output is correct |
40 |
Correct |
58 ms |
23216 KB |
Output is correct |
41 |
Correct |
78 ms |
28808 KB |
Output is correct |
42 |
Correct |
81 ms |
27920 KB |
Output is correct |
43 |
Correct |
51 ms |
19868 KB |
Output is correct |
44 |
Correct |
67 ms |
24736 KB |
Output is correct |
45 |
Correct |
62 ms |
20652 KB |
Output is correct |
46 |
Correct |
84 ms |
27312 KB |
Output is correct |
47 |
Correct |
67 ms |
23264 KB |
Output is correct |
48 |
Correct |
55 ms |
20668 KB |
Output is correct |
49 |
Correct |
40 ms |
11484 KB |
Output is correct |
50 |
Correct |
30 ms |
7932 KB |
Output is correct |
51 |
Correct |
57 ms |
16692 KB |
Output is correct |
52 |
Correct |
94 ms |
30004 KB |
Output is correct |
53 |
Correct |
84 ms |
26672 KB |
Output is correct |
54 |
Correct |
99 ms |
33072 KB |
Output is correct |
55 |
Correct |
52 ms |
19636 KB |
Output is correct |
56 |
Correct |
75 ms |
25384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
604 KB |
Output is correct |
6 |
Correct |
0 ms |
604 KB |
Output is correct |
7 |
Correct |
1 ms |
604 KB |
Output is correct |
8 |
Correct |
1 ms |
440 KB |
Output is correct |
9 |
Correct |
63 ms |
21676 KB |
Output is correct |
10 |
Correct |
73 ms |
25008 KB |
Output is correct |
11 |
Correct |
75 ms |
24752 KB |
Output is correct |
12 |
Correct |
77 ms |
26032 KB |
Output is correct |
13 |
Correct |
54 ms |
18096 KB |
Output is correct |
14 |
Correct |
59 ms |
22064 KB |
Output is correct |
15 |
Correct |
102 ms |
27308 KB |
Output is correct |
16 |
Correct |
98 ms |
26544 KB |
Output is correct |
17 |
Correct |
104 ms |
27568 KB |
Output is correct |
18 |
Correct |
82 ms |
19628 KB |
Output is correct |
19 |
Correct |
84 ms |
19024 KB |
Output is correct |
20 |
Correct |
93 ms |
23576 KB |
Output is correct |
21 |
Correct |
90 ms |
23368 KB |
Output is correct |
22 |
Correct |
86 ms |
22556 KB |
Output is correct |
23 |
Correct |
91 ms |
23344 KB |
Output is correct |
24 |
Correct |
89 ms |
21688 KB |
Output is correct |
25 |
Correct |
90 ms |
22820 KB |
Output is correct |
26 |
Correct |
85 ms |
22380 KB |
Output is correct |
27 |
Correct |
1 ms |
604 KB |
Output is correct |
28 |
Correct |
1 ms |
604 KB |
Output is correct |
29 |
Correct |
1 ms |
604 KB |
Output is correct |
30 |
Correct |
0 ms |
604 KB |
Output is correct |
31 |
Correct |
1 ms |
604 KB |
Output is correct |
32 |
Correct |
1 ms |
604 KB |
Output is correct |
33 |
Correct |
0 ms |
604 KB |
Output is correct |
34 |
Correct |
1 ms |
604 KB |
Output is correct |
35 |
Correct |
1 ms |
604 KB |
Output is correct |
36 |
Correct |
10 ms |
3540 KB |
Output is correct |
37 |
Correct |
80 ms |
27500 KB |
Output is correct |
38 |
Correct |
73 ms |
27680 KB |
Output is correct |
39 |
Correct |
73 ms |
26800 KB |
Output is correct |
40 |
Correct |
69 ms |
26120 KB |
Output is correct |
41 |
Correct |
69 ms |
25008 KB |
Output is correct |
42 |
Correct |
58 ms |
23216 KB |
Output is correct |
43 |
Correct |
78 ms |
28808 KB |
Output is correct |
44 |
Correct |
81 ms |
27920 KB |
Output is correct |
45 |
Correct |
51 ms |
19868 KB |
Output is correct |
46 |
Correct |
67 ms |
24736 KB |
Output is correct |
47 |
Correct |
14 ms |
3792 KB |
Output is correct |
48 |
Correct |
156 ms |
31848 KB |
Output is correct |
49 |
Correct |
168 ms |
31252 KB |
Output is correct |
50 |
Correct |
149 ms |
30484 KB |
Output is correct |
51 |
Correct |
143 ms |
29736 KB |
Output is correct |
52 |
Correct |
137 ms |
27152 KB |
Output is correct |
53 |
Correct |
108 ms |
21920 KB |
Output is correct |
54 |
Correct |
150 ms |
32400 KB |
Output is correct |
55 |
Correct |
157 ms |
31648 KB |
Output is correct |
56 |
Incorrect |
94 ms |
23896 KB |
Output isn't correct |
57 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
604 KB |
Output is correct |
7 |
Correct |
0 ms |
604 KB |
Output is correct |
8 |
Correct |
1 ms |
604 KB |
Output is correct |
9 |
Correct |
1 ms |
440 KB |
Output is correct |
10 |
Correct |
63 ms |
21676 KB |
Output is correct |
11 |
Correct |
73 ms |
25008 KB |
Output is correct |
12 |
Correct |
75 ms |
24752 KB |
Output is correct |
13 |
Correct |
77 ms |
26032 KB |
Output is correct |
14 |
Correct |
54 ms |
18096 KB |
Output is correct |
15 |
Correct |
59 ms |
22064 KB |
Output is correct |
16 |
Correct |
102 ms |
27308 KB |
Output is correct |
17 |
Correct |
98 ms |
26544 KB |
Output is correct |
18 |
Correct |
104 ms |
27568 KB |
Output is correct |
19 |
Correct |
82 ms |
19628 KB |
Output is correct |
20 |
Correct |
84 ms |
19024 KB |
Output is correct |
21 |
Correct |
93 ms |
23576 KB |
Output is correct |
22 |
Correct |
90 ms |
23368 KB |
Output is correct |
23 |
Correct |
86 ms |
22556 KB |
Output is correct |
24 |
Correct |
91 ms |
23344 KB |
Output is correct |
25 |
Correct |
89 ms |
21688 KB |
Output is correct |
26 |
Correct |
90 ms |
22820 KB |
Output is correct |
27 |
Correct |
85 ms |
22380 KB |
Output is correct |
28 |
Correct |
1 ms |
604 KB |
Output is correct |
29 |
Correct |
1 ms |
604 KB |
Output is correct |
30 |
Correct |
1 ms |
604 KB |
Output is correct |
31 |
Correct |
0 ms |
604 KB |
Output is correct |
32 |
Correct |
1 ms |
604 KB |
Output is correct |
33 |
Correct |
1 ms |
604 KB |
Output is correct |
34 |
Correct |
0 ms |
604 KB |
Output is correct |
35 |
Correct |
1 ms |
604 KB |
Output is correct |
36 |
Correct |
1 ms |
604 KB |
Output is correct |
37 |
Correct |
10 ms |
3540 KB |
Output is correct |
38 |
Correct |
80 ms |
27500 KB |
Output is correct |
39 |
Correct |
73 ms |
27680 KB |
Output is correct |
40 |
Correct |
73 ms |
26800 KB |
Output is correct |
41 |
Correct |
69 ms |
26120 KB |
Output is correct |
42 |
Correct |
69 ms |
25008 KB |
Output is correct |
43 |
Correct |
58 ms |
23216 KB |
Output is correct |
44 |
Correct |
78 ms |
28808 KB |
Output is correct |
45 |
Correct |
81 ms |
27920 KB |
Output is correct |
46 |
Correct |
51 ms |
19868 KB |
Output is correct |
47 |
Correct |
67 ms |
24736 KB |
Output is correct |
48 |
Correct |
14 ms |
3792 KB |
Output is correct |
49 |
Correct |
156 ms |
31848 KB |
Output is correct |
50 |
Correct |
168 ms |
31252 KB |
Output is correct |
51 |
Correct |
149 ms |
30484 KB |
Output is correct |
52 |
Correct |
143 ms |
29736 KB |
Output is correct |
53 |
Correct |
137 ms |
27152 KB |
Output is correct |
54 |
Correct |
108 ms |
21920 KB |
Output is correct |
55 |
Correct |
150 ms |
32400 KB |
Output is correct |
56 |
Correct |
157 ms |
31648 KB |
Output is correct |
57 |
Incorrect |
94 ms |
23896 KB |
Output isn't correct |
58 |
Halted |
0 ms |
0 KB |
- |