#include "Joi.h"
#include <bits/stdc++.h>
using namespace std;
void Joi(int n, int m, int u[], int v[], long long x, int t) {
vector<vector<int>> e(n);
for (int i = 0; i < m; i++) {
e[u[i]].push_back(v[i]);
e[v[i]].push_back(u[i]);
}
for (int i = 0; i < n; i++) {
sort(e[i].begin(), e[i].end());
}
vector<vector<int>> g(n);
vector<bool> was(n);
function<void(int, int)> MakeTree = [&](int v, int pv) {
was[v] = true;
for (int u : e[v]) {
if (was[u]) {
continue;
}
g[v].push_back(u);
g[u].push_back(v);
MakeTree(u, v);
}
};
MakeTree(0, 0);
const int L = 20;
vector<vector<int>> pr(n, vector<int>(L));
vector<int> dep(n);
function<void(int, int)> Dfs = [&](int v, int pv) {
pr[v][0] = pv;
for (int j = 1; j < L; j++) {
pr[v][j] = pr[pr[v][j - 1]][j - 1];
}
for (int u : g[v]) {
if (u == pv) {
continue;
}
dep[u] = dep[v] + 1;
Dfs(u, v);
}
};
Dfs(0, 0);
auto LCA = [&](int x, int y) {
if (dep[x] < dep[y]) {
swap(x, y);
}
for (int i = L - 1; i >= 0; i--) {
if (dep[pr[x][i]] >= dep[y]) {
x = pr[x][i];
}
}
if (x == y) {
return x;
}
for (int i = L - 1; i >= 0; i--) {
if (pr[x][i] != pr[y][i]) {
x = pr[x][i];
y = pr[y][i];
}
}
return pr[x][0];
};
auto GetDist = [&](int x, int y) {
return dep[x] + dep[y] - 2 * dep[LCA(x, y)];
};
vector<int> ver;
function<void(int, int)> Go = [&](int v, int pv) {
if (ver.size() == 60) {
return;
}
ver.push_back(v);
for (int u : g[v]) {
if (u == pv) {
continue;
}
Go(u, v);
}
};
Go(0, 0);
vector<vector<int>> ids(n);
for (int x : ver) {
ids[x] = ver;
}
vector<int> ans(n);
for (int i = 0; i < 60; i++) {
ans[ver[i]] = (x >> i & 1);
}
function<void(int, int)> Solve = [&](int v, int pv) {
if (ids[v].empty()) {
ids[v] = ids[pv];
int idx = 0;
for (int i = 1; i < 60; i++) {
if (GetDist(ids[v][i], v) > GetDist(ids[v][idx], v)) {
idx = i;
}
}
ans[v] = ans[ids[v][idx]];
ids[v][idx] = v;
}
for (int u : g[v]) {
if (u == pv) {
continue;
}
Solve(u, v);
}
};
Solve(0, 0);
for (int i = 0; i < n; i++) {
MessageBoard(i, ans[i]);
}
}
#include "Ioi.h"
#include <bits/stdc++.h>
using namespace std;
long long Ioi(int n, int m, int u[], int v[], int p, int me, int t) {
vector<vector<int>> e(n);
for (int i = 0; i < m; i++) {
e[u[i]].push_back(v[i]);
e[v[i]].push_back(u[i]);
}
for (int i = 0; i < n; i++) {
sort(e[i].begin(), e[i].end());
}
vector<vector<int>> g(n);
vector<bool> was(n);
function<void(int, int)> MakeTree = [&](int v, int pv) {
was[v] = true;
for (int u : e[v]) {
if (was[u]) {
continue;
}
g[v].push_back(u);
g[u].push_back(v);
MakeTree(u, v);
}
};
MakeTree(0, 0);
const int L = 20;
vector<vector<int>> pr(n, vector<int>(L));
vector<int> dep(n);
function<void(int, int)> Dfs = [&](int v, int pv) {
pr[v][0] = pv;
for (int j = 1; j < L; j++) {
pr[v][j] = pr[pr[v][j - 1]][j - 1];
}
for (int u : g[v]) {
if (u == pv) {
continue;
}
dep[u] = dep[v] + 1;
Dfs(u, v);
}
};
Dfs(0, 0);
auto LCA = [&](int x, int y) {
if (dep[x] < dep[y]) {
swap(x, y);
}
for (int i = L - 1; i >= 0; i--) {
if (dep[pr[x][i]] >= dep[y]) {
x = pr[x][i];
}
}
if (x == y) {
return x;
}
for (int i = L - 1; i >= 0; i--) {
if (pr[x][i] != pr[y][i]) {
x = pr[x][i];
y = pr[y][i];
}
}
return pr[x][0];
};
auto GetDist = [&](int x, int y) {
return dep[x] + dep[y] - 2 * dep[LCA(x, y)];
};
vector<int> ver;
function<void(int, int)> Go = [&](int v, int pv) {
if (ver.size() == 60) {
return;
}
ver.push_back(v);
for (int u : g[v]) {
if (u == pv) {
continue;
}
Go(u, v);
}
};
Go(0, 0);
vector<vector<int>> ids(n);
for (int x : ver) {
ids[x] = ver;
}
function<void(int, int)> Solve = [&](int v, int pv) {
if (ids[v].empty()) {
ids[v] = ids[pv];
int idx = 0;
for (int i = 1; i < 60; i++) {
if (GetDist(ids[v][i], v) > GetDist(ids[v][idx], v)) {
idx = i;
}
}
ids[v][idx] = v;
}
for (int u : g[v]) {
if (u == pv) {
continue;
}
Solve(u, v);
}
};
Solve(0, 0);
vector<int> bit(n, -1);
for (int i = 0; i < 60; i++) {
bit[ids[p][i]] = i;
}
vector<int> f(n);
f[p] = me;
function<void(int, int)> FindBits = [&](int v, int pv) {
for (int u : g[v]) {
if (bit[u] == -1 || u == pv) {
continue;
}
f[u] = Move(u);
FindBits(u, v);
f[v] = Move(v);
}
};
FindBits(p, p);
long long res = 0;
for (int i = 0; i < n; i++) {
if (bit[i] != -1) {
res += (1LL << bit[i]) * f[i];
}
}
return res;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
836 KB |
Output is correct |
2 |
Correct |
4 ms |
768 KB |
Output is correct |
3 |
Correct |
10 ms |
1028 KB |
Output is correct |
4 |
Correct |
2 ms |
768 KB |
Output is correct |
5 |
Correct |
2 ms |
768 KB |
Output is correct |
6 |
Correct |
6 ms |
836 KB |
Output is correct |
7 |
Correct |
10 ms |
1028 KB |
Output is correct |
8 |
Correct |
10 ms |
1028 KB |
Output is correct |
9 |
Correct |
10 ms |
852 KB |
Output is correct |
10 |
Correct |
4 ms |
776 KB |
Output is correct |
11 |
Correct |
6 ms |
1236 KB |
Output is correct |
12 |
Correct |
0 ms |
780 KB |
Output is correct |
13 |
Correct |
10 ms |
1032 KB |
Output is correct |
14 |
Correct |
10 ms |
1040 KB |
Output is correct |
15 |
Correct |
10 ms |
1000 KB |
Output is correct |
16 |
Correct |
11 ms |
1036 KB |
Output is correct |
17 |
Correct |
10 ms |
1044 KB |
Output is correct |
18 |
Correct |
12 ms |
904 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
299 ms |
13736 KB |
Output is correct |
2 |
Correct |
300 ms |
14020 KB |
Output is correct |
3 |
Correct |
297 ms |
14032 KB |
Output is correct |
4 |
Correct |
415 ms |
11624 KB |
Output is correct |
5 |
Correct |
297 ms |
12864 KB |
Output is correct |
6 |
Correct |
284 ms |
12424 KB |
Output is correct |
7 |
Correct |
295 ms |
12596 KB |
Output is correct |
8 |
Correct |
299 ms |
12616 KB |
Output is correct |
9 |
Correct |
328 ms |
12780 KB |
Output is correct |
10 |
Correct |
400 ms |
11696 KB |
Output is correct |
11 |
Correct |
402 ms |
11636 KB |
Output is correct |
12 |
Correct |
386 ms |
10508 KB |
Output is correct |
13 |
Correct |
334 ms |
10644 KB |
Output is correct |
14 |
Correct |
354 ms |
11208 KB |
Output is correct |
15 |
Correct |
424 ms |
11452 KB |
Output is correct |
16 |
Correct |
415 ms |
11536 KB |
Output is correct |
17 |
Correct |
417 ms |
11700 KB |
Output is correct |
18 |
Correct |
398 ms |
11560 KB |
Output is correct |
19 |
Correct |
376 ms |
11456 KB |
Output is correct |
20 |
Correct |
275 ms |
12892 KB |
Output is correct |
21 |
Correct |
270 ms |
12872 KB |
Output is correct |
22 |
Correct |
292 ms |
12304 KB |
Output is correct |
23 |
Correct |
284 ms |
12640 KB |
Output is correct |
24 |
Correct |
295 ms |
12348 KB |
Output is correct |
25 |
Correct |
309 ms |
12580 KB |
Output is correct |
26 |
Correct |
300 ms |
12684 KB |
Output is correct |
27 |
Correct |
318 ms |
12640 KB |
Output is correct |
28 |
Correct |
300 ms |
12960 KB |
Output is correct |
29 |
Correct |
272 ms |
11600 KB |
Output is correct |
30 |
Correct |
293 ms |
12032 KB |
Output is correct |
31 |
Correct |
5 ms |
752 KB |
Output is correct |
32 |
Correct |
6 ms |
784 KB |
Output is correct |
33 |
Correct |
10 ms |
1040 KB |
Output is correct |
34 |
Correct |
4 ms |
748 KB |
Output is correct |
35 |
Correct |
3 ms |
780 KB |
Output is correct |
36 |
Correct |
2 ms |
740 KB |
Output is correct |
37 |
Correct |
2 ms |
776 KB |
Output is correct |
38 |
Correct |
2 ms |
772 KB |
Output is correct |
39 |
Correct |
1 ms |
748 KB |
Output is correct |
40 |
Correct |
2 ms |
880 KB |
Output is correct |
41 |
Correct |
3 ms |
752 KB |
Output is correct |
42 |
Correct |
1 ms |
772 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
768 KB |
Output is correct |
2 |
Correct |
2 ms |
776 KB |
Output is correct |
3 |
Correct |
2 ms |
764 KB |
Output is correct |
4 |
Correct |
51 ms |
2720 KB |
Output is correct |
5 |
Correct |
44 ms |
2756 KB |
Output is correct |
6 |
Correct |
46 ms |
2768 KB |
Output is correct |
7 |
Correct |
44 ms |
2852 KB |
Output is correct |
8 |
Correct |
46 ms |
2792 KB |
Output is correct |
9 |
Correct |
278 ms |
14168 KB |
Output is correct |
10 |
Correct |
276 ms |
14060 KB |
Output is correct |
11 |
Correct |
271 ms |
14192 KB |
Output is correct |
12 |
Correct |
0 ms |
776 KB |
Output is correct |
13 |
Correct |
1 ms |
776 KB |
Output is correct |
14 |
Correct |
0 ms |
768 KB |
Output is correct |
15 |
Correct |
1 ms |
768 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
291 ms |
13640 KB |
Output is correct |
2 |
Correct |
295 ms |
14128 KB |
Output is correct |
3 |
Correct |
292 ms |
14140 KB |
Output is correct |
4 |
Correct |
397 ms |
11928 KB |
Output is correct |
5 |
Correct |
290 ms |
13628 KB |
Output is correct |
6 |
Correct |
300 ms |
12724 KB |
Output is correct |
7 |
Correct |
290 ms |
12684 KB |
Output is correct |
8 |
Correct |
285 ms |
12096 KB |
Output is correct |
9 |
Correct |
287 ms |
12316 KB |
Output is correct |
10 |
Correct |
403 ms |
11704 KB |
Output is correct |
11 |
Correct |
406 ms |
11592 KB |
Output is correct |
12 |
Correct |
338 ms |
10668 KB |
Output is correct |
13 |
Correct |
368 ms |
10568 KB |
Output is correct |
14 |
Correct |
355 ms |
11044 KB |
Output is correct |
15 |
Correct |
372 ms |
11540 KB |
Output is correct |
16 |
Correct |
433 ms |
11544 KB |
Output is correct |
17 |
Correct |
378 ms |
11480 KB |
Output is correct |
18 |
Correct |
384 ms |
11588 KB |
Output is correct |
19 |
Correct |
379 ms |
11540 KB |
Output is correct |
20 |
Correct |
275 ms |
13000 KB |
Output is correct |
21 |
Correct |
271 ms |
12796 KB |
Output is correct |
22 |
Correct |
289 ms |
12624 KB |
Output is correct |
23 |
Correct |
287 ms |
12384 KB |
Output is correct |
24 |
Correct |
291 ms |
12436 KB |
Output is correct |
25 |
Correct |
287 ms |
12668 KB |
Output is correct |
26 |
Correct |
287 ms |
12616 KB |
Output is correct |
27 |
Correct |
290 ms |
12868 KB |
Output is correct |
28 |
Correct |
296 ms |
12300 KB |
Output is correct |
29 |
Correct |
266 ms |
11692 KB |
Output is correct |
30 |
Correct |
269 ms |
12060 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
299 ms |
13764 KB |
Output is correct |
2 |
Correct |
294 ms |
14064 KB |
Output is correct |
3 |
Correct |
293 ms |
14152 KB |
Output is correct |
4 |
Correct |
386 ms |
11640 KB |
Output is correct |
5 |
Correct |
288 ms |
14068 KB |
Output is correct |
6 |
Correct |
290 ms |
12540 KB |
Output is correct |
7 |
Correct |
286 ms |
12320 KB |
Output is correct |
8 |
Correct |
309 ms |
12716 KB |
Output is correct |
9 |
Correct |
292 ms |
12584 KB |
Output is correct |
10 |
Correct |
399 ms |
11664 KB |
Output is correct |
11 |
Correct |
402 ms |
11720 KB |
Output is correct |
12 |
Correct |
336 ms |
10648 KB |
Output is correct |
13 |
Correct |
365 ms |
10548 KB |
Output is correct |
14 |
Correct |
353 ms |
10976 KB |
Output is correct |
15 |
Correct |
379 ms |
11548 KB |
Output is correct |
16 |
Correct |
374 ms |
11540 KB |
Output is correct |
17 |
Correct |
408 ms |
11560 KB |
Output is correct |
18 |
Correct |
413 ms |
11672 KB |
Output is correct |
19 |
Correct |
392 ms |
11640 KB |
Output is correct |
20 |
Correct |
279 ms |
12952 KB |
Output is correct |
21 |
Correct |
271 ms |
12880 KB |
Output is correct |
22 |
Correct |
288 ms |
12804 KB |
Output is correct |
23 |
Correct |
294 ms |
12540 KB |
Output is correct |
24 |
Correct |
290 ms |
12428 KB |
Output is correct |
25 |
Correct |
297 ms |
12512 KB |
Output is correct |
26 |
Correct |
314 ms |
12316 KB |
Output is correct |
27 |
Correct |
300 ms |
12876 KB |
Output is correct |
28 |
Correct |
307 ms |
13060 KB |
Output is correct |
29 |
Correct |
275 ms |
11908 KB |
Output is correct |
30 |
Correct |
303 ms |
12092 KB |
Output is correct |
31 |
Correct |
5 ms |
780 KB |
Output is correct |
32 |
Correct |
6 ms |
752 KB |
Output is correct |
33 |
Correct |
11 ms |
980 KB |
Output is correct |
34 |
Correct |
4 ms |
780 KB |
Output is correct |
35 |
Correct |
2 ms |
772 KB |
Output is correct |
36 |
Correct |
2 ms |
776 KB |
Output is correct |
37 |
Correct |
2 ms |
768 KB |
Output is correct |
38 |
Correct |
1 ms |
736 KB |
Output is correct |
39 |
Correct |
2 ms |
768 KB |
Output is correct |
40 |
Correct |
2 ms |
772 KB |
Output is correct |
41 |
Correct |
3 ms |
1016 KB |
Output is correct |
42 |
Correct |
2 ms |
772 KB |
Output is correct |