#include "Joi.h"
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <cmath>
#include <iomanip>
#include <cassert>
using namespace std;
typedef pair<int, int> P;
#define rep(i, n) for (int i=0; i<(n); i++)
#define all(c) (c).begin(), (c).end()
#define uniq(c) c.erase(unique(all(c)), (c).end())
#define _1 first
#define _2 second
#define pb push_back
#define INF 1145141919
#define MOD 1000000007
struct UF {
int N;
vector<int> U, R;
UF(int N) : N(N), U(N), R(N, 1) {
rep(i, N) U[i] = i;
}
int find(int x) {
if (U[x] == x) return x;
return U[x] = find(U[x]);
}
void unite(int x, int y) {
x = find(x), y = find(y);
if (x == y) return;
if (R[x] < R[y]) swap(x, y);
U[y] = x;
R[x] += R[y];
}
bool same(int x, int y) {
return find(x) == find(y);
}
};
void Joi(int N, int M, int GA[], int GB[], long long X, int T) {
int A[10000] = {};
vector<int> G[10000];
int deg[10000] = {};
set<int> S[10000], leaf[10000];
UF uf(N);
rep(i, M) {
int a = GA[i], b = GB[i];
if (!uf.same(a, b)) {
G[a].pb(b), G[b].pb(a);
uf.unite(a, b);
}
}
rep(i, N) A[i] = -1;
set<int> used, lf;
queue<P> q;
q.push(P(0, -1));
rep(i, 60) {
int x = q.front()._1, p = q.front()._2; q.pop();
A[x] = i;
used.insert(x);
deg[x]++;
if (p != -1) deg[p]++;
for (int t : G[x]) if (t != p) q.push(P(t, x));
}
rep(i, N) if (deg[i] == 1) lf.insert(i);
for (int x : used) S[x] = used, leaf[x] = lf;
while (!q.empty()) {
int x = q.front()._1, p = q.front()._2; q.pop();
S[x] = set<int>(S[p]);
S[x].insert(x);
leaf[x] = set<int>(leaf[p]);
if (leaf[x].find(p) != leaf[x].end()) leaf[x].erase(p);
int from = *leaf[x].begin();
leaf[x].erase(from);
S[x].erase(from);
A[x] = A[from];
leaf[x].insert(x);
for (int t : G[x]) if (t != p) q.push(P(t, x));
}
rep(i, N) assert(S[i].size() == 60);
rep(i, N) MessageBoard(i, (X>>A[i])&1);
}
#include "Ioi.h"
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <cmath>
#include <iomanip>
#include <cassert>
using namespace std;
typedef pair<int, int> P;
#define rep(i, n) for (int i=0; i<(n); i++)
#define all(c) (c).begin(), (c).end()
#define uniq(c) c.erase(unique(all(c)), (c).end())
#define _1 first
#define _2 second
#define pb push_back
#define INF 1145141919
#define MOD 1000000007
struct UF {
int N;
vector<int> U, R;
UF(int N) : N(N), U(N), R(N, 1) {
rep(i, N) U[i] = i;
}
int find(int x) {
if (U[x] == x) return x;
return U[x] = find(U[x]);
}
void unite(int x, int y) {
x = find(x), y = find(y);
if (x == y) return;
if (R[x] < R[y]) swap(x, y);
U[y] = x;
R[x] += R[y];
}
bool same(int x, int y) {
return find(x) == find(y);
}
};
long long Ioi(int N, int M, int GA[], int GB[], int start, int V, int T) {
int A[10000] = {};
vector<int> G[10000];
int deg[10000] = {};
set<int> S[10000], leaf[10000];
UF uf(N);
rep(i, M) {
int a = GA[i], b = GB[i];
if (!uf.same(a, b)) {
G[a].pb(b), G[b].pb(a);
uf.unite(a, b);
}
}
rep(i, N) A[i] = -1;
set<int> used, lf;
queue<P> q;
q.push(P(0, -1));
rep(i, 60) {
int x = q.front()._1, p = q.front()._2; q.pop();
A[x] = i;
used.insert(x);
deg[x]++;
if (p != -1) deg[p]++;
for (int t : G[x]) if (t != p) q.push(P(t, x));
}
rep(i, N) if (deg[i] == 1) lf.insert(i);
for (int x : used) S[x] = used, leaf[x] = lf;
while (!q.empty()) {
int x = q.front()._1, p = q.front()._2; q.pop();
S[x] = set<int>(S[p]);
S[x].insert(x);
leaf[x] = set<int>(leaf[p]);
if (leaf[x].find(p) != leaf[x].end()) leaf[x].erase(p);
int from = *leaf[x].begin();
leaf[x].erase(from);
S[x].erase(from);
A[x] = A[from];
leaf[x].insert(x);
for (int t : G[x]) if (t != p) q.push(P(t, x));
}
rep(i, N) assert(S[i].size() == 60);
long long X = 0;
function<void(int, int, int)> dfs = [&](int x, int p, int v) {
X |= ((long long)v<<A[x]);
for (int t : G[x]) if (t != p && S[start].find(t) != S[start].end()) {
dfs(t, x, Move(t));
Move(x);
}
};
dfs(start, -1, V);
return X;
}
Compilation message
Ioi.cpp: In function 'long long int Ioi(int, int, int*, int*, int, int, int)':
Ioi.cpp:90:3: error: 'function' was not declared in this scope
function<void(int, int, int)> dfs = [&](int x, int p, int v) {
^
Ioi.cpp:90:30: error: expression list treated as compound expression in functional cast [-fpermissive]
function<void(int, int, int)> dfs = [&](int x, int p, int v) {
^
Ioi.cpp:90:12: error: expected primary-expression before 'void'
function<void(int, int, int)> dfs = [&](int x, int p, int v) {
^
Ioi.cpp:97:19: error: 'dfs' was not declared in this scope
dfs(start, -1, V);
^