This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "Joi.h"
#include <bits/stdc++.h>
using namespace std;
void Joi(int N, int M, int A[], int B[], long long X, int T) {
struct DSU {
vector<int> p;
DSU() = default;
DSU(int n) : p(n) {
iota(p.begin(), p.end(), 0);
}
int leader(int x) {
while (x != p[x]) x = p[x] = p[p[x]];
return x;
}
bool unite(int x, int y) {
x = leader(x), y = leader(y);
if (p[y] == x) {
return false;
} else {
return p[y] = x, true;
}
}
};
vector<int> tin(N), par(N, -1);
vector<vector<int>> g(N), adj(N);
DSU d(N);
for (int i = 0; i < M; ++i) {
if (d.unite(A[i], B[i])) {
g[A[i]].push_back(B[i]);
g[B[i]].push_back(A[i]);
}
}
int timer = 0;
function<void(int)> dfs = [&](int v) {
tin[v] = timer++;
sort(g[v].begin(), g[v].end());
for (int to : g[v]) {
if (to != par[v]) {
par[to] = v;
adj[v].push_back(to);
dfs(to);
}
}
};
dfs(228 % N);
for (int i = 0; i < N; ++i) {
MessageBoard(i, X >> (tin[i] % 60) & 1);
}
}
#include "Ioi.h"
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
long long Ioi(int N, int M, int A[], int B[], int P, int V, int T) {
struct DSU {
vector<int> p;
DSU() = default;
DSU(int n) : p(n) {
iota(p.begin(), p.end(), 0);
}
int leader(int x) {
while (x != p[x]) x = p[x] = p[p[x]];
return x;
}
bool unite(int x, int y) {
x = leader(x), y = leader(y);
if (p[y] == x) {
return false;
} else {
return p[y] = x, true;
}
}
};
vector<int> tin(N), par(N, -1);
vector<vector<int>> g(N), adj(N);
DSU d(N);
for (int i = 0; i < M; ++i) {
if (d.unite(A[i], B[i])) {
g[A[i]].push_back(B[i]);
g[B[i]].push_back(A[i]);
}
}
int timer = 0;
function<void(int)> dfs = [&](int v) {
tin[v] = timer++;
sort(g[v].begin(), g[v].end());
for (int to : g[v]) {
if (to != par[v]) {
par[to] = v;
adj[v].push_back(to);
dfs(to);
}
}
};
dfs(228 % N);
int LOG = 60;
vector<bool> used(N);
vector<int> ans(LOG, -1);
ans[tin[P] % LOG] = V;
vector<int> last(N, -1);
int x = P;
while (find(ans.begin(), ans.end(), -1) != ans.end()) {
used[x] = true;
auto it = upper_bound(adj[x].begin(), adj[x].end(), last[x]);
if (it == adj[x].end()) {
it = adj[x].begin();
}
if (adj[x].empty() || used[*it]) {
last[par[x]] = x;
x = par[x];
assert(x != -1);
ans[tin[x] % LOG] = Move(x);
} else {
last[x] = *it;
x = *it;
ans[tin[x] % LOG] = Move(x);
}
}
ll X = 0;
for (int i = 0; i < LOG; ++i) {
assert(ans[i] != -1);
X += ans[i] * (1LL << i);
}
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... |