/* In the name of Allah */
#include<bits/stdc++.h>
#include<Joi.h>
using namespace std;
const int N = 1e4 + 5, LG = 60;
int n, m, k, a[N], b[N], root[N], h[N], sz[N], par[N], id[N];
vector<int> ed[N], adj[N];
bitset<N> mark;
void dfs_tree(int u) {
mark.set(u);
vector<int> help;
for (auto v: ed[u])
if (!mark[v]) {
help.push_back(v);
dfs_tree(v), par[v] = u;
}
adj[u] = help;
}
void change(int u) {
for (auto v: adj[u])
if (!~root[v]) {
root[v] = root[u];
change(v);
}
}
void go(int u) {
id[u] = sz[root[u]]++;
for (auto v: adj[u])
if (k + sz[root[u]] < LG)
go(v);
}
void go_big(int u) {
for (sz[u] = 0; true; u = adj[u][0]) {
id[u] = sz[root[u]]++;
if (adj[u].empty())
break;
k = sz[adj[u][0]];
for (auto v: adj[u])
if (v ^ adj[u][0] && k + sz[root[u]] < LG)
go(v);
}
}
bool build(int u) {
vector<int> help;
sz[u] = 1, h[u] = 0;
for (auto v: adj[u])
if (!build(v)) {
sz[u] += sz[v];
help.push_back(v);
h[u] = max(h[u], h[v] + 1);
}
sort(help.begin(), help.end(), [] (int u, int v) {
return h[u] > h[v];
});
adj[u] = help;
if (sz[u] < LG)
return false;
change(root[u] = u);
return go_big(u), true;
}
bool calc(int u) {
memset(root, -1, sizeof root);
memset(id, -1, sizeof id);
mark.reset(), dfs_tree(u);
return build(u);
}
void build_tree() {
if (!calc(0))
for (int v = 0; v < n; v++)
if (~root[v] && !~root[par[v]]) {
calc(v);
break;
}
}
void Joi(int N, int M, int A[], int B[], long long X, int T) {
n = N, m = M;
for (int u = 0; u < n; u++)
ed[u].clear();
for (int i = 0; i < m; i++) {
ed[a[i] = A[i]].push_back(B[i]);
ed[b[i] = B[i]].push_back(A[i]);
}
build_tree();
for (int u = 0; u < n; u++)
MessageBoard(u, ~id[u]? X >> id[u] & 1: 0);
}
/* In the name of Allah */
#include<bits/stdc++.h>
#include<Ioi.h>
using namespace std;
const int N = 1e4 + 5, LG = 60;
int n, m, k, a[N], b[N], root[N], h[N], sz[N], par[N], id[N];
vector<int> ed[N], adj[N], path[N];
bitset<N> mark;
void dfs_tree(int u) {
mark.set(u);
vector<int> help;
for (auto v: ed[u])
if (!mark[v]) {
help.push_back(v);
dfs_tree(v), par[v] = u;
}
adj[u] = help;
}
void change(int u) {
for (auto v: adj[u])
if (!~root[v]) {
root[v] = root[u];
change(v);
}
}
void go(int u) {
id[u] = sz[root[u]]++;
path[root[u]].push_back(u);
for (auto v: adj[u])
if (k + sz[root[u]] < LG)
go(v), path[root[u]].push_back(u);
}
void go_big(int u) {
for (sz[u] = 0; true; u = adj[u][0]) {
path[root[u]].push_back(u);
id[u] = sz[root[u]]++;
if (adj[u].empty())
break;
k = sz[adj[u][0]];
for (auto v: adj[u])
if (v ^ adj[u][0] && k + sz[root[u]] < LG)
go(v), path[root[u]].push_back(u);
}
}
bool build(int u) {
vector<int> help;
sz[u] = 1, h[u] = 0;
for (auto v: adj[u])
if (!build(v)) {
sz[u] += sz[v];
help.push_back(v);
h[u] = max(h[u], h[v] + 1);
}
sort(help.begin(), help.end(), [] (int u, int v) {
return h[u] > h[v];
});
adj[u] = help;
if (sz[u] < LG)
return false;
change(root[u] = u);
return go_big(u), true;
}
bool calc(int u) {
for (int v = 0; v < n; v++)
path[v].clear();
memset(root, -1, sizeof root);
memset(id, -1, sizeof id);
mark.reset(), dfs_tree(u);
return build(u);
}
void build_tree() {
if (!calc(u))
for (int v = 0; v < n; v++)
if (~root[v] && !~root[par[v]]) {
calc(v);
break;
}
}
long long Ioi(int N, int M, int A[], int B[], int P, int V, int T) {
n = N, m = M;
for (int u = 0; u < n; u++)
ed[u].clear();
for (int i = 0; i < m; i++) {
ed[a[i] = A[i]].push_back(B[i]);
ed[b[i] = B[i]].push_back(A[i]);
}
build_tree();
while (P ^ root[P])
V = Move(P = par[P]);
long long answer = V;
for (auto u: path[P]) {
if (P ^ u)
V = Move(P = u);
answer |= 1LL * V << id[P];
}
return answer;
}
Compilation message
Ioi.cpp: In function 'void build_tree()':
Ioi.cpp:79:12: error: 'u' was not declared in this scope
if (!calc(u))
^