-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstarter.cpp
More file actions
347 lines (307 loc) · 6.17 KB
/
Copy pathstarter.cpp
File metadata and controls
347 lines (307 loc) · 6.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
#include <bits/stdc++.h>
// #include <iostream>
// #include <string>
// #include <sstream>
// #include <cstdlib>
// #include <cmath>
// #include <vector>
// #include <list>
// #include <stack>
// #include <queue>
// #include <deque>
// #include <set>
// #include <unordered_set>
// #include <map>
// #include <unordered_map>
// #include <algorithm>
// #include <fstream>
// #include <iomanip>
// #include <cstring>
// #include <chrono>
using namespace std;
using namespace std::chrono;
#define _CRT_SECURE_NO_WARNINGS
#define FAST ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define NEWLINE cout << '\n'
#define loop(n) for(int i = 0; i < n; i++)
#define forn(itr, stt, end) for(int itr = stt; itr < end; itr++)
#define READ_ARR(A) forn(meowmeow, 0, A.size()) cin >> A[meowmeow];
#define all(A) A.begin(), A.end()
#define YN cout << (cn ? "YES" : "NO") << '\n'
#define INF 1000000009
const double PI = acos(-1);
#define EXTERNAL_FILES 0
#if EXTERNAL_FILES
ifstream fin("hello.in");
//ofstream fout("output.txt");
#define cin fin
//#define cout fout
#endif
#define MEASURE_TIME 0
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> ii;
typedef pair<ll, ll> pll;
typedef vector<ii> vii;
typedef vector<pll> vpll;
typedef priority_queue<int, vi, greater<int>> minheap;
ll gcd(ll a, ll b) {
if (b == 0)
return a;
return gcd(b, a % b);
}
ll lcm(ll a, ll b) {
return (a / gcd(a, b)) * b;
}
bool isPrime(ll n) {
if (n <= 1) return false;
for (ll i = 2; i * i <= n; i++) {
if (n % i == 0) return false;
}
return true;
}
inline vector<ll> sieve(ll n) {
vector<bool> isPrime(n + 1, true);
for (ll i = 2; i * i <= n; i++) {
if (isPrime[i])
for (int j = 2 * i; j <= n; j += i) {
isPrime[j] = false;
}
}
vector<ll> primes;
for (ll i = 2; i <= n; i++)
if (isPrime[i]) primes.push_back(i);
return primes;
}
inline vector<bool> sieveQuery(int n) {
vector<bool> isPrime(n + 1, true);
for (int i = 2; i <= sqrt(n); i++) {
if (isPrime[i])
for (int j = 2 * i; j <= n; j += i) {
isPrime[j] = false;
}
}
return isPrime;
}
inline vector<ll> primeFactors(ll n) {
vector<ll> F;
for (ll i = 2LL; i * i <= n; i++) {
while (n % i == 0) {
F.push_back(i);
n /= i;
}
}
if (n > 1) F.push_back(n);
return F;
}
inline vector<ll> unsorted_factors(ll n) {
vector<ll> F;
ll i = 1;
for (; i * i < n; i++) {
if (n % i == 0) {
F.push_back(i);
F.push_back(n / i);
}
}
if (i * i == n) F.push_back(i);
return F;
}
void shift_right(vll& A, int x) {
int n = A.size();
x %= n;
vll B(n);
for (int i = 0; i < n; i++)
B[(i + x) % n] = A[i];
A = B;
}
string itos(ll n) {
string s;
while (n) {
s += char(n % 10 + 48);
n /= 10;
}
reverse(all(s));
return s;
}
int cnt_dig(int n) {
int cnt = 0;
while (n) {
cnt++;
n /= 10;
}
return cnt;
}
vi digits(ll n) {
vi Sol;
while (n) {
Sol.push_back(n % 10);
n /= 10;
}
return Sol;
}
ll digsum(ll n){
ll sum = 0;
while(n){
sum += n%10;
n /= 10;
}
return sum;
}
ll max3(ll a, ll b, ll c){
return max(max(a, b), c);
}
string binary(ll n) {
string bin;
while (n) {
bin += (n % 2LL ? '1' : '0');
n /= 2;
}
reverse(bin.begin(), bin.end());
return bin;
}
bool isPalindrome(string& s) {
for (int i = 0, j = s.size() - 1; i < j; i++, j--)
if (s[i] != s[j]) return 0;
return 1;
}
void trim(string&s){
int start = 0, end = s.size()-1;
while(s[start] == ' ' && start < s.size()) start++;
while(s[end] == ' ' && end >= 0) end--;
s = s.substr(start, end-start+1);
}
void hashSort(vll& A){
map<ll, ll> F;
for(auto a : A) F[a]++;
ll i = 0;
for(auto it : F){
while(it.second--){
A[i++] = it.first;
}
}
}
#define MAXNODES 100009
int bfs(const vector<vi>& G, int start) {
int distance = 0, maxDist = 0;
queue<int> q;
vector<bool> visited(200000, false);
vi dist(G.size() + 1, -1);
visited[start] = true;
q.push(start);
while (!q.empty()) {
int u = q.front(); q.pop();
visited[u] = true;
for (int i : G[u]) if (!visited[i]) {
q.push(i);
dist[i] = dist[u] + 1;
maxDist = max(maxDist, dist[i]);
}
}
// return dist;
return maxDist;
}
class DSU{
private:
int parent[MAXNODES];
int groupSize[MAXNODES];
int edgesCount[MAXNODES];
public:
DSU(){
for (int i = 0; i < MAXNODES; i++){
parent[i] = i;
groupSize[i] = 1;
edgesCount[i] = 0;
}
}
int findLeader(int i){
if (parent[i] == i) return i;
return parent[i] = findLeader(parent[i]);
}
bool sameGroup(int x, int y){
int leader1 = findLeader(x);
int leader2 = findLeader(y);
return leader1 == leader2;
}
void merge(int x, int y){
int leader1 = findLeader(x);
int leader2 = findLeader(y);
if (leader1 == leader2){
edgesCount[leader1]++;
return;
}
if (groupSize[leader1] > groupSize[leader2]){
parent[leader2] = leader1;
groupSize[leader1] += groupSize[leader2];
edgesCount[leader1] += edgesCount[leader2] + 1;
}
else{
parent[leader1] = leader2;
groupSize[leader2] += groupSize[leader1];
edgesCount[leader2] += edgesCount[leader1] + 1;
}
}
int getSize(int x){
int leader = findLeader(x);
return groupSize[leader];
}
int getEdgesCount(int x){
int leader = findLeader(x);
return edgesCount[leader];
}
};
template <class T>
class fenwick {
private:
vector<T> tree;
int n;
public:
fenwick(int n) : n(n) { tree.assign(n + 1, 0); }
T query(int l, int r) { return query(r) - query(l - 1); }
T query(int r) {
T s = 0;
while (r > 0) s += tree[r], r -= (r & (-r));
return s;
}
void update(int i, T v) {
while (i <= n) tree[i] += v, i += (i & (-i));
}
};
#define MAX 1000009
const ll MOD = 998244353;//1e9 + 7;
#define EXTERNAL_OUT 0
#if EXTERNAL_OUT
ofstream fout("output.txt");
#define cout fout
#endif
void init() {
}
// ll n, m, a, b, x, y;
bool can(string& s, int k){
return 1;
}
void solve(){
ll n; cin >> n;
NEWLINE; //cout.flush();
}
int main()
{
FAST;
init();
int _t_ = 1; cin >> _t_;
#if MEASURE_TIME
auto start = high_resolution_clock::now();
#endif
while (_t_--)
solve();
#if MEASURE_TIME
auto stop = high_resolution_clock::now();
auto duration = duration_cast<microseconds>(stop - start);
cout << duration.count() << endl;
#endif
#if EXTERNAL_OUT || EXTERNAL_FILES
fout.close();
// system("output.txt");
#endif
return 0;
}