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;
#define sp ' '
#define endl '\n'
#define fi first
#define se second
#define mp make_pair
#define bit(x,y) ((x>>(y))&1LL)
#define NMAX 10000
#define MMAX 20000
#define MOVEMAX 20000
struct dsu {
int par[NMAX + 5];
dsu() {
for (int i = 0; i < NMAX; i++) par[i] = i;
}
int find(int x) {
if (par[x] == x) return x;
return par[x] = find(par[x]);
}
void uni(int x, int y) {
x = find(x); y = find(y);
if (x != y) par[x] = y;
}
} d;
int Time = 0; int sta[NMAX + 5], par[NMAX + 5];
vector<vector<int> > a(NMAX + 5);
void dfs(int u, int p) {
sta[u] = ++Time;
for (auto v : a[u]) {
if (v == p) continue;
par[v] = u;
dfs(v, u);
}
}
void makeTree(int N, int M, int A[], int B[]) {
for (int i = 0; i < M; i++) {
if (d.find(A[i]) != d.find(B[i])) {
d.uni(A[i], B[i]);
a[A[i]].push_back(B[i]);
a[B[i]].push_back(A[i]);
}
}
dfs(0, 0);
}
// end of the common part
void Joi(int N, int M, int A[], int B[], long long X, int T) {
makeTree(N, M, A, B);
for (int i = 0; i < N; i++)
MessageBoard(i, bit(X, sta[i] % 60));
}
#include "Ioi.h"
#include <bits/stdc++.h>
using namespace std;
#define sp ' '
#define endl '\n'
#define fi first
#define se second
#define mp make_pair
#define bit(x,y) ((x>>(y))&1LL)
#define NMAX 10000
#define MMAX 20000
#define MOVEMAX 20000
struct dsu {
int par[NMAX + 5];
dsu() {
for (int i = 0; i < NMAX; i++) par[i] = i;
}
int find(int x) {
if (par[x] == x) return x;
return par[x] = find(par[x]);
}
void uni(int x, int y) {
x = find(x); y = find(y);
if (x != y) par[x] = y;
}
} d;
int Time = 0; int sta[NMAX + 5], par[NMAX + 5];
vector<vector<int> > a(NMAX + 5);
int mark[60]; bool visited[NMAX + 5]; int rem;
void dfs(int u, int p) {
sta[u] = ++Time;
for (auto v : a[u]) {
if (v == p) continue;
par[v] = u;
dfs(v, u);
}
}
void makeTree(int N, int M, int A[], int B[]) {
for (int i = 0; i < M; i++) {
if (d.find(A[i]) != d.find(B[i])) {
d.uni(A[i], B[i]);
a[A[i]].push_back(B[i]);
a[B[i]].push_back(A[i]);
}
}
dfs(0, 0);
}
int Lab(int u) {
return sta[u] % 60;
}
void dfs(int u, int root, int Z, int from) {
if (mark[Lab(u)] == -1) {
mark[Lab(u)] = Z; rem--;
if (rem == 0) throw 1;
}
visited[u] = true;
if (u == root) {
int p = 0;
for (int i = 0; i < a[u].size(); i++) {
int v = a[u][i];
if (v == from) {
p = i; break;
}
}
for (int i = p; i < a[u].size(); i++) {
int v = a[u][i];
if (v == par[u] || visited[v]) continue;
dfs(v, root, Move(v), from);
}
for (int i = p; i >= 0; i--) {
int v = a[u][i];
if (v == par[u] || visited[v]) continue;
dfs(v, root, Move(v), from);
}
}
else {
for (int i = 0; i < a[u].size(); i++) {
int v = a[u][i];
if (v == par[u] || visited[v]) continue;
dfs(v, root, Move(v), from);
}
}
if (u != root) {
Move(par[u]);
}
else {
dfs(par[u], par[u], Move(par[u]), u);
}
}
long long Ioi(int N, int M, int A[], int B[], int P, int V, int T) {
long long ret = 0;
makeTree(N, M, A, B);
memset(mark, -1, sizeof(mark)); rem = 60;
try {
dfs(P, P, V, P);
}
catch (...) {
for (int i = 0; i < 60; i++) {
if (mark[i] == 1) ret += (1LL << i);
}
}
return ret;
}
Compilation message (stderr)
Ioi.cpp: In function 'void dfs(int, int, int, int)':
Ioi.cpp:60:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i = 0; i < a[u].size(); i++) {
^
Ioi.cpp:66:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i = p; i < a[u].size(); i++) {
^
Ioi.cpp:78:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i = 0; i < a[u].size(); i++) {
^
# | 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... |