#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>> g(n);
for (int i = 0; i < n - 1; i++) {
g[u[i]].push_back(v[i]);
g[v[i]].push_back(u[i]);
}
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>> g(n);
for (int i = 0; i < n - 1; i++) {
g[u[i]].push_back(v[i]);
g[v[i]].push_back(u[i]);
}
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);
for (int i = 0; i < n; i++) {
if (ids[i].size() != 60) {
return 0LL;
}
}
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 (u == pv || bit[u] == -1) {
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 |
776 KB |
Output is correct |
2 |
Correct |
4 ms |
768 KB |
Output is correct |
3 |
Correct |
10 ms |
752 KB |
Output is correct |
4 |
Correct |
2 ms |
768 KB |
Output is correct |
5 |
Correct |
2 ms |
776 KB |
Output is correct |
6 |
Correct |
6 ms |
776 KB |
Output is correct |
7 |
Correct |
10 ms |
900 KB |
Output is correct |
8 |
Correct |
10 ms |
780 KB |
Output is correct |
9 |
Correct |
10 ms |
780 KB |
Output is correct |
10 |
Correct |
4 ms |
768 KB |
Output is correct |
11 |
Runtime error |
356 ms |
262144 KB |
Execution killed with signal 9 |
12 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
634 ms |
262144 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
776 KB |
Output is correct |
2 |
Correct |
2 ms |
768 KB |
Output is correct |
3 |
Correct |
3 ms |
776 KB |
Output is correct |
4 |
Correct |
46 ms |
2572 KB |
Output is correct |
5 |
Correct |
50 ms |
2468 KB |
Output is correct |
6 |
Correct |
44 ms |
2524 KB |
Output is correct |
7 |
Correct |
44 ms |
2596 KB |
Output is correct |
8 |
Correct |
43 ms |
2588 KB |
Output is correct |
9 |
Correct |
276 ms |
13112 KB |
Output is correct |
10 |
Correct |
282 ms |
13068 KB |
Output is correct |
11 |
Correct |
279 ms |
13004 KB |
Output is correct |
12 |
Correct |
1 ms |
776 KB |
Output is correct |
13 |
Correct |
2 ms |
768 KB |
Output is correct |
14 |
Correct |
1 ms |
768 KB |
Output is correct |
15 |
Correct |
1 ms |
768 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
726 ms |
262144 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
423 ms |
262144 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |