#include "Joi.h"
#include <bits/stdc++.h>
using namespace std;
#define all(x) x.begin(), x.end()
static vector<int> adj[10000], order;
static int seen[10000], depth[10000];
static bool ans[10000];
static void dfs(int i) {
seen[i] = true;
order.emplace_back(i);
for (int j: adj[i]) {
if (seen[j]) continue;
depth[j] = depth[i] + 1;
dfs(j);
}
}
void Joi(int N, int M, int A[], int B[], long long X, int T) {
while (M--) {
adj[A[M]].emplace_back(B[M]);
adj[B[M]].emplace_back(A[M]);
}
dfs(0);
if (*max_element(depth, depth + N) >= 59) {
for (int i = N; i--;) MessageBoard(i, (X >> (depth[i] % 60)) & 1);
return;
}
memset(seen, false, sizeof seen);
vector<int> sub(order.begin(), order.begin() + 60);
for (int i = 60; i--;) {
seen[sub[i]] = true;
MessageBoard(sub[i], ans[sub[i]] = (X >> i) & 1);
}
for (int i = 60; i < N; ++i) {
seen[order[i]] = true;
for (int j: sub) {
int cnt = 0;
for (int k: adj[j]) cnt += seen[k] != 2;
if (cnt > 1) continue;
MessageBoard(order[i], ans[order[i]] = ans[j]);
sub.erase(find(all(sub), j));
seen[j] = 2;
break;
}
sub.emplace_back(order[i]);
}
}
#include "Ioi.h"
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define all(x) x.begin(), x.end()
static vector<int> adj[10000], order;
static int seen[10000], depth[10000], par[10000], idx[10000];
static ll X;
static void dfs(int i) {
seen[i] = true;
order.emplace_back(i);
for (int j: adj[i]) {
if (seen[j]) continue;
depth[j] = depth[par[j] = i] + 1;
dfs(j);
}
}
static void dfs2(int i) {
seen[i] = false;
for (int j: adj[i]) {
if (seen[j] != 1) continue;
X |= (ll) Move(j) << idx[j];
dfs2(j);
Move(i);
}
}
ll Ioi(int N, int M, int A[], int B[], int P, int V, int T) {
while (M--) {
adj[A[M]].emplace_back(B[M]);
adj[B[M]].emplace_back(A[M]);
}
dfs(0);
if (*max_element(depth, depth + N) >= 59) {
if (depth[P] >= 59) {
X = (ll) V << (depth[P] % 60);
for (int i = 59; i--; P = par[P]) X |= (ll) Move(par[P]) << (depth[par[P]] % 60);
return X;
}
X = V;
while (P) X = Move(P = par[P]);
for (int i = N; i--;) {
if (depth[i] == 59) {
order = {i};
while (order.back()) order.emplace_back(par[order.back()]);
reverse(all(order));
for (int i = 1; i < 60; ++i) X |= (ll) Move(order[i]) << i;
return X;
}
}
assert(false);
}
memset(seen, false, sizeof seen);
vector<int> sub(order.begin(), order.begin() + 60);
for (int i = 60; i--;) {
seen[sub[i]] = true;
idx[sub[i]] = i;
}
for (int i = 60; not seen[P]; ++i) {
seen[order[i]] = true;
for (int j: sub) {
int cnt = 0;
for (int k: adj[j]) cnt += seen[k] != 2;
if (cnt > 1) continue;
idx[order[i]] = idx[j];
sub.erase(find(all(sub), j));
seen[j] = 2;
break;
}
sub.emplace_back(order[i]);
}
X = (ll) V << idx[P];
dfs2(P);
return X;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |