#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);
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 |
772 KB |
Output is correct |
2 |
Correct |
5 ms |
772 KB |
Output is correct |
3 |
Correct |
11 ms |
872 KB |
Output is correct |
4 |
Correct |
2 ms |
748 KB |
Output is correct |
5 |
Correct |
3 ms |
744 KB |
Output is correct |
6 |
Correct |
4 ms |
780 KB |
Output is correct |
7 |
Correct |
10 ms |
1092 KB |
Output is correct |
8 |
Correct |
10 ms |
776 KB |
Output is correct |
9 |
Correct |
10 ms |
872 KB |
Output is correct |
10 |
Correct |
4 ms |
780 KB |
Output is correct |
11 |
Runtime error |
355 ms |
262144 KB |
Execution killed with signal 9 |
12 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
631 ms |
262144 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
780 KB |
Output is correct |
2 |
Correct |
2 ms |
780 KB |
Output is correct |
3 |
Correct |
2 ms |
784 KB |
Output is correct |
4 |
Correct |
43 ms |
2496 KB |
Output is correct |
5 |
Correct |
45 ms |
2688 KB |
Output is correct |
6 |
Correct |
44 ms |
2516 KB |
Output is correct |
7 |
Correct |
43 ms |
2516 KB |
Output is correct |
8 |
Correct |
44 ms |
2560 KB |
Output is correct |
9 |
Correct |
275 ms |
13208 KB |
Output is correct |
10 |
Correct |
270 ms |
13224 KB |
Output is correct |
11 |
Correct |
274 ms |
13228 KB |
Output is correct |
12 |
Correct |
1 ms |
780 KB |
Output is correct |
13 |
Correct |
2 ms |
772 KB |
Output is correct |
14 |
Correct |
0 ms |
780 KB |
Output is correct |
15 |
Correct |
0 ms |
748 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
701 ms |
262144 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
403 ms |
262144 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |