// You can't change other people; you can only change yourself.
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include "swap.h"
// Pragmas
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
// Namespaces
#define yume using
#define wo namespace
#define kanaeyo std
#define nazotte __gnu_pbds
yume wo kanaeyo;
yume wo nazotte;
// Data types
using i8 = __int128;
using ll = long long;
using si = short int;
using ld = long double;
// Pairs
using pi8 = pair<i8, i8>;
using pll = pair<ll, ll>;
using pii = pair<int, int>;
using psi = pair<si, si>;
using pld = pair<ld, ld>;
#define fi first
#define se second
// PBDS
template<typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;
// Quick macro functions
#define sqr(x) ((x)*(x))
#define pow2(x) (1ll << (x))
#define debug(x) cout << #x << " = " << (x) << '\n'
#define debugV(x, a) cout << #x << "[" << (a) << "] = " << (x[a]) << '\n'
// Check min and max
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
// Modular arithmetic
template<typename T> void maddto(T &a, T b, T mod) {a += b; a %= mod;}
template<typename T> void msubto(T &a, T b, T mod) {a -= b; while (a < 0) a += mod; a %= mod;}
template<typename T> void mmulto(T &a, T b, T mod) {a *= b; a %= mod;}
template<typename T> T madd(T a, T b, T mod) {a += b; a %= mod; return a;}
template<typename T> T msub(T a, T b, T mod) {a -= b; while (a < 0) a += mod; return a;}
template<typename T> T mmul(T a, T b, T mod) {a *= b; a %= mod; return a;}
// Constants
const ll ModA = 998244353;
const ll ModC = 1e9 + 7;
const ll INF = 1e18;
const ll iINF = 1e9;
const ld EPS = 1e-9;
const ld iEPS = 1e-6;
struct OnlineDSU {
int n;
vector<vector<pii>> par, sz, degree, maxdegree, edgecount;
OnlineDSU(int _n) {
n = _n;
for (int i = 0; i < n; i++) {
par.push_back({{0, i}});
}
sz.assign(n, {{0, 1}});
degree.assign(n, {{0, 0}});
maxdegree.assign(n, {{0, 0}});
edgecount.assign(n, {{0, 0}});
}
void insert(vector<pii> &v, int val, int t) {
if (v.back().se == val) {return;}
if (v.back().fi == t) {
v.back().se = val;
} else {
v.push_back({t, val});
}
}
int query(vector<pii> &v, int t) {
pii search = {t+1, -iINF};
auto it = upper_bound(v.begin(), v.end(), search);
it--;
return it->second;
}
int parent_latest(int x) {return par[x].back().se;}
int size_latest(int x) {return sz[x].back().se;}
int degree_latest(int x) {return degree[x].back().se;}
int maxdegree_latest(int x) {return maxdegree[x].back().se;}
int edgecount_latest(int x) {return edgecount[x].back().se;}
int get_degree(int x, int t) {return query(degree[x], t);}
int get_maxdegree(int x, int t) {return query(maxdegree[x], t);}
int get_edgecount(int x, int t) {return query(edgecount[x], t);}
int get_size(int x, int t) {return query(sz[x], t);}
int rep_latest(int x, int t) {
if (x == parent_latest(x)) {return x;}
insert(par[x], rep_latest(parent_latest(x), t), t);
return parent_latest(x);
}
int rep(int x, int t) {
int p = query(par[x], t);
if (x == p) {return x;}
return rep(p, t);
}
void join_latest(int u, int v, int t) {
insert(degree[u], degree_latest(u)+1, t);
insert(degree[v], degree_latest(v)+1, t);
int x = rep_latest(u, t), y = rep_latest(v, t);
if (x != y) {
if (size_latest(x) < size_latest(y)) {swap(x, y);}
insert(par[y], x, t);
insert(sz[x], size_latest(x) + size_latest(y), t);
int mx = maxdegree_latest(x), my = maxdegree_latest(y);
insert(maxdegree[x], max(max(mx, my), max(degree_latest(u), degree_latest(v))), t);
int ex = edgecount_latest(x), ey = edgecount_latest(y);
insert(edgecount[x], ex+ey+1, t);
} else {
insert(maxdegree[x], max(degree_latest(u), degree_latest(v)), t);
int e = edgecount_latest(x);
insert(edgecount[x], e+1, t);
}
}
bool check(int u, int v, int t) {
int x = rep(u, t), y = rep(v, t);
return (x == y);
}
};
void print(vector<vector<pii>> &v) {
for (int i = 0; i < v.size(); i++) {
cout << i << ": ";
for (auto j : v[i]) {
cout << "{" << j.fi << ", " << j.se << "} ";
}
cout << '\n';
}
cout << '\n';
}
using Edge = pair<int, pii>;
OnlineDSU *D;
void init(int N, int M, vector<int> U, vector<int> V, vector<int> W) {
vector<Edge> E;
for (int i = 0; i < M; i++) {
E.push_back({W[i], {U[i], V[i]}});
}
sort(E.begin(), E.end());
D = new OnlineDSU(N);
for (auto x : E) {
D->join_latest(x.se.fi, x.se.se, x.fi);
//printf("%d: %d %d\n", x.fi, x.se.fi, x.se.se);
}
/*
cout << "par\n";
print(D->par);
cout << "sz\n";
print(D->sz);
cout << "degree\n";
print(D->degree);
cout << "maxdegree\n";
print(D->maxdegree);
cout << "edgecount\n";
print(D->edgecount);
*/
}
const int MAX = 1e9;
int getMinimumFuelCapacity(int X, int Y) {
int L = 1, R = MAX, ans = -1;
while (L <= R) {
int M = (L + R) >> 1;
bool pos = 1;
if (!D->check(X, Y, M)) {
pos = 0;
} else {
int R = D->rep(X, M);
if (D->get_maxdegree(R, M) > 2 || (D->get_size(R, M) == D->get_edgecount(R, M))) {
pos = 1;
} else {
pos = 0;
}
}
if (pos) {
R = M - 1;
ans = M;
} else {
L = M + 1;
}
}
return ans;
}
//int main() {}
Compilation message
swap.cpp: In function 'void print(std::vector<std::vector<std::pair<int, int> > >&)':
swap.cpp:152:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<std::pair<int, int> > >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
152 | for (int i = 0; i < v.size(); i++) {
| ~~^~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
468 KB |
Output is correct |
5 |
Correct |
1 ms |
580 KB |
Output is correct |
6 |
Correct |
1 ms |
596 KB |
Output is correct |
7 |
Correct |
1 ms |
692 KB |
Output is correct |
8 |
Correct |
2 ms |
596 KB |
Output is correct |
9 |
Correct |
155 ms |
30184 KB |
Output is correct |
10 |
Correct |
205 ms |
36924 KB |
Output is correct |
11 |
Correct |
187 ms |
36148 KB |
Output is correct |
12 |
Correct |
207 ms |
38260 KB |
Output is correct |
13 |
Correct |
140 ms |
36008 KB |
Output is correct |
14 |
Correct |
211 ms |
30200 KB |
Output is correct |
15 |
Correct |
838 ms |
38588 KB |
Output is correct |
16 |
Correct |
832 ms |
37548 KB |
Output is correct |
17 |
Correct |
873 ms |
39740 KB |
Output is correct |
18 |
Correct |
623 ms |
37176 KB |
Output is correct |
19 |
Correct |
469 ms |
9808 KB |
Output is correct |
20 |
Correct |
830 ms |
42932 KB |
Output is correct |
21 |
Correct |
870 ms |
41832 KB |
Output is correct |
22 |
Correct |
922 ms |
44348 KB |
Output is correct |
23 |
Correct |
630 ms |
41728 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
505 ms |
36540 KB |
Output is correct |
4 |
Correct |
500 ms |
38552 KB |
Output is correct |
5 |
Correct |
512 ms |
37396 KB |
Output is correct |
6 |
Correct |
480 ms |
38332 KB |
Output is correct |
7 |
Correct |
509 ms |
37952 KB |
Output is correct |
8 |
Correct |
486 ms |
36484 KB |
Output is correct |
9 |
Correct |
507 ms |
37740 KB |
Output is correct |
10 |
Correct |
499 ms |
36180 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
468 KB |
Output is correct |
5 |
Correct |
1 ms |
580 KB |
Output is correct |
6 |
Correct |
1 ms |
596 KB |
Output is correct |
7 |
Correct |
1 ms |
692 KB |
Output is correct |
8 |
Correct |
2 ms |
596 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
2 ms |
596 KB |
Output is correct |
11 |
Correct |
1 ms |
596 KB |
Output is correct |
12 |
Correct |
1 ms |
596 KB |
Output is correct |
13 |
Correct |
1 ms |
564 KB |
Output is correct |
14 |
Correct |
1 ms |
564 KB |
Output is correct |
15 |
Correct |
1 ms |
724 KB |
Output is correct |
16 |
Correct |
1 ms |
692 KB |
Output is correct |
17 |
Correct |
1 ms |
596 KB |
Output is correct |
18 |
Correct |
2 ms |
596 KB |
Output is correct |
19 |
Incorrect |
2 ms |
596 KB |
Output isn't correct |
20 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
468 KB |
Output is correct |
6 |
Correct |
1 ms |
580 KB |
Output is correct |
7 |
Correct |
1 ms |
596 KB |
Output is correct |
8 |
Correct |
1 ms |
692 KB |
Output is correct |
9 |
Correct |
2 ms |
596 KB |
Output is correct |
10 |
Correct |
155 ms |
30184 KB |
Output is correct |
11 |
Correct |
205 ms |
36924 KB |
Output is correct |
12 |
Correct |
187 ms |
36148 KB |
Output is correct |
13 |
Correct |
207 ms |
38260 KB |
Output is correct |
14 |
Correct |
140 ms |
36008 KB |
Output is correct |
15 |
Correct |
2 ms |
596 KB |
Output is correct |
16 |
Correct |
1 ms |
596 KB |
Output is correct |
17 |
Correct |
1 ms |
596 KB |
Output is correct |
18 |
Correct |
1 ms |
564 KB |
Output is correct |
19 |
Correct |
1 ms |
564 KB |
Output is correct |
20 |
Correct |
1 ms |
724 KB |
Output is correct |
21 |
Correct |
1 ms |
692 KB |
Output is correct |
22 |
Correct |
1 ms |
596 KB |
Output is correct |
23 |
Correct |
2 ms |
596 KB |
Output is correct |
24 |
Incorrect |
2 ms |
596 KB |
Output isn't correct |
25 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
468 KB |
Output is correct |
5 |
Correct |
1 ms |
580 KB |
Output is correct |
6 |
Correct |
1 ms |
596 KB |
Output is correct |
7 |
Correct |
1 ms |
692 KB |
Output is correct |
8 |
Correct |
2 ms |
596 KB |
Output is correct |
9 |
Correct |
155 ms |
30184 KB |
Output is correct |
10 |
Correct |
205 ms |
36924 KB |
Output is correct |
11 |
Correct |
187 ms |
36148 KB |
Output is correct |
12 |
Correct |
207 ms |
38260 KB |
Output is correct |
13 |
Correct |
140 ms |
36008 KB |
Output is correct |
14 |
Correct |
211 ms |
30200 KB |
Output is correct |
15 |
Correct |
838 ms |
38588 KB |
Output is correct |
16 |
Correct |
832 ms |
37548 KB |
Output is correct |
17 |
Correct |
873 ms |
39740 KB |
Output is correct |
18 |
Correct |
623 ms |
37176 KB |
Output is correct |
19 |
Correct |
505 ms |
36540 KB |
Output is correct |
20 |
Correct |
500 ms |
38552 KB |
Output is correct |
21 |
Correct |
512 ms |
37396 KB |
Output is correct |
22 |
Correct |
480 ms |
38332 KB |
Output is correct |
23 |
Correct |
509 ms |
37952 KB |
Output is correct |
24 |
Correct |
486 ms |
36484 KB |
Output is correct |
25 |
Correct |
507 ms |
37740 KB |
Output is correct |
26 |
Correct |
499 ms |
36180 KB |
Output is correct |
27 |
Correct |
2 ms |
596 KB |
Output is correct |
28 |
Correct |
1 ms |
596 KB |
Output is correct |
29 |
Correct |
1 ms |
596 KB |
Output is correct |
30 |
Correct |
1 ms |
564 KB |
Output is correct |
31 |
Correct |
1 ms |
564 KB |
Output is correct |
32 |
Correct |
1 ms |
724 KB |
Output is correct |
33 |
Correct |
1 ms |
692 KB |
Output is correct |
34 |
Correct |
1 ms |
596 KB |
Output is correct |
35 |
Correct |
2 ms |
596 KB |
Output is correct |
36 |
Correct |
14 ms |
5452 KB |
Output is correct |
37 |
Correct |
220 ms |
38484 KB |
Output is correct |
38 |
Correct |
198 ms |
38288 KB |
Output is correct |
39 |
Correct |
202 ms |
38388 KB |
Output is correct |
40 |
Correct |
198 ms |
37956 KB |
Output is correct |
41 |
Correct |
191 ms |
37436 KB |
Output is correct |
42 |
Correct |
174 ms |
34200 KB |
Output is correct |
43 |
Correct |
204 ms |
38380 KB |
Output is correct |
44 |
Correct |
199 ms |
38332 KB |
Output is correct |
45 |
Correct |
139 ms |
35700 KB |
Output is correct |
46 |
Correct |
192 ms |
37844 KB |
Output is correct |
47 |
Correct |
54 ms |
5152 KB |
Output is correct |
48 |
Correct |
888 ms |
39996 KB |
Output is correct |
49 |
Correct |
833 ms |
40108 KB |
Output is correct |
50 |
Correct |
853 ms |
39968 KB |
Output is correct |
51 |
Correct |
808 ms |
39672 KB |
Output is correct |
52 |
Correct |
754 ms |
37316 KB |
Output is correct |
53 |
Correct |
558 ms |
28060 KB |
Output is correct |
54 |
Correct |
894 ms |
40380 KB |
Output is correct |
55 |
Correct |
956 ms |
40032 KB |
Output is correct |
56 |
Correct |
401 ms |
37692 KB |
Output is correct |
57 |
Correct |
663 ms |
39864 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
468 KB |
Output is correct |
6 |
Correct |
1 ms |
580 KB |
Output is correct |
7 |
Correct |
1 ms |
596 KB |
Output is correct |
8 |
Correct |
1 ms |
692 KB |
Output is correct |
9 |
Correct |
2 ms |
596 KB |
Output is correct |
10 |
Correct |
155 ms |
30184 KB |
Output is correct |
11 |
Correct |
205 ms |
36924 KB |
Output is correct |
12 |
Correct |
187 ms |
36148 KB |
Output is correct |
13 |
Correct |
207 ms |
38260 KB |
Output is correct |
14 |
Correct |
140 ms |
36008 KB |
Output is correct |
15 |
Correct |
211 ms |
30200 KB |
Output is correct |
16 |
Correct |
838 ms |
38588 KB |
Output is correct |
17 |
Correct |
832 ms |
37548 KB |
Output is correct |
18 |
Correct |
873 ms |
39740 KB |
Output is correct |
19 |
Correct |
623 ms |
37176 KB |
Output is correct |
20 |
Correct |
505 ms |
36540 KB |
Output is correct |
21 |
Correct |
500 ms |
38552 KB |
Output is correct |
22 |
Correct |
512 ms |
37396 KB |
Output is correct |
23 |
Correct |
480 ms |
38332 KB |
Output is correct |
24 |
Correct |
509 ms |
37952 KB |
Output is correct |
25 |
Correct |
486 ms |
36484 KB |
Output is correct |
26 |
Correct |
507 ms |
37740 KB |
Output is correct |
27 |
Correct |
499 ms |
36180 KB |
Output is correct |
28 |
Correct |
2 ms |
596 KB |
Output is correct |
29 |
Correct |
1 ms |
596 KB |
Output is correct |
30 |
Correct |
1 ms |
596 KB |
Output is correct |
31 |
Correct |
1 ms |
564 KB |
Output is correct |
32 |
Correct |
1 ms |
564 KB |
Output is correct |
33 |
Correct |
1 ms |
724 KB |
Output is correct |
34 |
Correct |
1 ms |
692 KB |
Output is correct |
35 |
Correct |
1 ms |
596 KB |
Output is correct |
36 |
Correct |
2 ms |
596 KB |
Output is correct |
37 |
Correct |
14 ms |
5452 KB |
Output is correct |
38 |
Correct |
220 ms |
38484 KB |
Output is correct |
39 |
Correct |
198 ms |
38288 KB |
Output is correct |
40 |
Correct |
202 ms |
38388 KB |
Output is correct |
41 |
Correct |
198 ms |
37956 KB |
Output is correct |
42 |
Correct |
191 ms |
37436 KB |
Output is correct |
43 |
Correct |
174 ms |
34200 KB |
Output is correct |
44 |
Correct |
204 ms |
38380 KB |
Output is correct |
45 |
Correct |
199 ms |
38332 KB |
Output is correct |
46 |
Correct |
139 ms |
35700 KB |
Output is correct |
47 |
Correct |
192 ms |
37844 KB |
Output is correct |
48 |
Correct |
54 ms |
5152 KB |
Output is correct |
49 |
Correct |
888 ms |
39996 KB |
Output is correct |
50 |
Correct |
833 ms |
40108 KB |
Output is correct |
51 |
Correct |
853 ms |
39968 KB |
Output is correct |
52 |
Correct |
808 ms |
39672 KB |
Output is correct |
53 |
Correct |
754 ms |
37316 KB |
Output is correct |
54 |
Correct |
558 ms |
28060 KB |
Output is correct |
55 |
Correct |
894 ms |
40380 KB |
Output is correct |
56 |
Correct |
956 ms |
40032 KB |
Output is correct |
57 |
Correct |
401 ms |
37692 KB |
Output is correct |
58 |
Correct |
663 ms |
39864 KB |
Output is correct |
59 |
Correct |
469 ms |
9808 KB |
Output is correct |
60 |
Correct |
830 ms |
42932 KB |
Output is correct |
61 |
Correct |
870 ms |
41832 KB |
Output is correct |
62 |
Correct |
922 ms |
44348 KB |
Output is correct |
63 |
Correct |
630 ms |
41728 KB |
Output is correct |
64 |
Incorrect |
2 ms |
596 KB |
Output isn't correct |
65 |
Halted |
0 ms |
0 KB |
- |