#include "Joi.h"
#include <vector>
#include <algorithm>
using ll = long long;
const int NMAX = 10'000;
std::vector<int> g[NMAX + 1];
int value[NMAX + 1];
bool vis[NMAX + 1];
std::vector<int> order;
void dfs(int u) {
order.push_back(u);
vis[u] = true;
for (const auto &v : g[u]) {
if (!vis[v]) {
dfs(v);
}
}
}
void Joi(int n, int m, int a[], int b[], long long X, int T) {
for (int i = 0; i < m; i++) {
g[a[i]].push_back(b[i]);
g[b[i]].push_back(a[i]);
}
for (int i = 0; i < n; i++) {
std::sort(g[i].begin(), g[i].end());
}
dfs(0);
for (int i = 0; i < 60; i++) {
value[order[i]] = ((ll) X >> i) & 1LL;
}
for (int i = 0; i < n; i++) {
MessageBoard(i, value[i]);
}
}
#include "Ioi.h"
#include <vector>
#include <algorithm>
using ll = long long;
const int NMAX = 10'000;
std::vector<int> g[NMAX + 1];
int value[NMAX + 1];
bool vis[NMAX + 1];
int parent[NMAX + 1];
std::vector<int> order;
void dfs(int u) {
order.push_back(u);
vis[u] = true;
for (const auto &v : g[u]) {
if (!vis[v]) {
parent[v] = u;
dfs(v);
}
}
}
bool hasSon(int u, int v) { // v e fiu al lui u?
for (const auto &w : g[u]) {
if (v == w) {
return true;
}
}
return false;
}
long long Ioi(int n, int m, int a[], int b[], int P, int V, int T) {
for (int i = 0; i < m; i++) {
g[a[i]].push_back(b[i]);
g[b[i]].push_back(a[i]);
}
for (int i = 0; i < n; i++) {
assert(!vis[i]);
std::sort(g[i].begin(), g[i].end());
}
dfs(0);
int u = P;
ll answer = 0;
if (u == 0) {
Move(g[0][0]);
answer = Move(0);
}
while (u != 0) {
u = parent[u];
answer = Move(u);
}
for (int i = 1; i < 60; i++) {
while (!hasSon(u, order[i])) {
u = parent[u];
}
if (Move(order[i])) {
answer |= (1LL << i);
}
u = order[i];
}
return answer;
}
Compilation message
Ioi.cpp: In function 'long long int Ioi(int, int, int*, int*, int, int, int)':
Ioi.cpp:40:5: error: 'assert' was not declared in this scope
40 | assert(!vis[i]);
| ^~~~~~
Ioi.cpp:4:1: note: 'assert' is defined in header '<cassert>'; did you forget to '#include <cassert>'?
3 | #include <algorithm>
+++ |+#include <cassert>
4 |