#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, bool free) {
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, free);
}
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, free);
}
}
else {
if (free) {
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, free);
}
}
else {
for (int i = a[u].size() - 1; i >= 0; i--) {
int v = a[u][i];
if (v == par[u] || visited[v]) continue;
dfs(v, root, Move(v), from, free);
}
}
}
if (u != root) {
Move(par[u]);
}
else {
dfs(par[u], par[u], Move(par[u]), u, 0);
}
}
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, 1);
}
catch (...) {
for (int i = 0; i < 60; i++) {
if (mark[i] == 1) ret += (1LL << i);
}
}
return ret;
}
Compilation message
Ioi.cpp: In function 'void dfs(int, int, int, int, bool)':
Ioi.cpp:60:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i = 0; i < a[u].size(); i++) {
^
Ioi.cpp:66:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i = p; i < a[u].size(); i++) {
^
Ioi.cpp:79:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i = 0; i < a[u].size(); i++) {
^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
5608 KB |
Output is correct |
2 |
Correct |
3 ms |
5608 KB |
Output is correct |
3 |
Correct |
3 ms |
5612 KB |
Output is correct |
4 |
Correct |
0 ms |
5608 KB |
Output is correct |
5 |
Correct |
0 ms |
5608 KB |
Output is correct |
6 |
Correct |
0 ms |
5608 KB |
Output is correct |
7 |
Correct |
0 ms |
5612 KB |
Output is correct |
8 |
Correct |
3 ms |
5616 KB |
Output is correct |
9 |
Correct |
0 ms |
5612 KB |
Output is correct |
10 |
Correct |
0 ms |
5608 KB |
Output is correct |
11 |
Correct |
0 ms |
5608 KB |
Output is correct |
12 |
Correct |
3 ms |
5608 KB |
Output is correct |
13 |
Correct |
3 ms |
5612 KB |
Output is correct |
14 |
Correct |
3 ms |
5612 KB |
Output is correct |
15 |
Correct |
0 ms |
5612 KB |
Output is correct |
16 |
Correct |
3 ms |
5612 KB |
Output is correct |
17 |
Correct |
0 ms |
5612 KB |
Output is correct |
18 |
Correct |
3 ms |
5612 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
32 ms |
6256 KB |
Output is correct |
2 |
Correct |
35 ms |
6284 KB |
Output is correct |
3 |
Correct |
32 ms |
6284 KB |
Output is correct |
4 |
Correct |
18 ms |
6256 KB |
Output is correct |
5 |
Correct |
12 ms |
6324 KB |
Output is correct |
6 |
Correct |
26 ms |
6296 KB |
Output is correct |
7 |
Correct |
15 ms |
6336 KB |
Output is correct |
8 |
Correct |
25 ms |
6376 KB |
Output is correct |
9 |
Correct |
12 ms |
6380 KB |
Output is correct |
10 |
Correct |
19 ms |
6384 KB |
Output is correct |
11 |
Correct |
18 ms |
6384 KB |
Output is correct |
12 |
Correct |
18 ms |
6152 KB |
Output is correct |
13 |
Correct |
15 ms |
6152 KB |
Output is correct |
14 |
Correct |
15 ms |
6136 KB |
Output is correct |
15 |
Correct |
16 ms |
6284 KB |
Output is correct |
16 |
Correct |
19 ms |
6256 KB |
Output is correct |
17 |
Correct |
18 ms |
6256 KB |
Output is correct |
18 |
Correct |
22 ms |
6256 KB |
Output is correct |
19 |
Correct |
18 ms |
6256 KB |
Output is correct |
20 |
Correct |
12 ms |
6368 KB |
Output is correct |
21 |
Correct |
15 ms |
6360 KB |
Output is correct |
22 |
Correct |
19 ms |
6148 KB |
Output is correct |
23 |
Correct |
12 ms |
6260 KB |
Output is correct |
24 |
Correct |
22 ms |
6172 KB |
Output is correct |
25 |
Correct |
22 ms |
6228 KB |
Output is correct |
26 |
Correct |
18 ms |
6276 KB |
Output is correct |
27 |
Correct |
26 ms |
6272 KB |
Output is correct |
28 |
Correct |
22 ms |
6300 KB |
Output is correct |
29 |
Correct |
18 ms |
6224 KB |
Output is correct |
30 |
Correct |
18 ms |
6196 KB |
Output is correct |
31 |
Correct |
3 ms |
5608 KB |
Output is correct |
32 |
Correct |
0 ms |
5608 KB |
Output is correct |
33 |
Correct |
3 ms |
5616 KB |
Output is correct |
34 |
Correct |
0 ms |
5608 KB |
Output is correct |
35 |
Correct |
0 ms |
5608 KB |
Output is correct |
36 |
Correct |
0 ms |
5608 KB |
Output is correct |
37 |
Correct |
3 ms |
5608 KB |
Output is correct |
38 |
Correct |
0 ms |
5608 KB |
Output is correct |
39 |
Correct |
0 ms |
5608 KB |
Output is correct |
40 |
Correct |
3 ms |
5608 KB |
Output is correct |
41 |
Correct |
3 ms |
5608 KB |
Output is correct |
42 |
Correct |
0 ms |
5608 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
5608 KB |
Output is correct |
2 |
Correct |
3 ms |
5608 KB |
Output is correct |
3 |
Correct |
0 ms |
5608 KB |
Output is correct |
4 |
Correct |
3 ms |
5756 KB |
Output is correct |
5 |
Correct |
3 ms |
5756 KB |
Output is correct |
6 |
Correct |
3 ms |
5756 KB |
Output is correct |
7 |
Correct |
3 ms |
5756 KB |
Output is correct |
8 |
Correct |
3 ms |
5756 KB |
Output is correct |
9 |
Correct |
9 ms |
6820 KB |
Output is correct |
10 |
Correct |
22 ms |
6820 KB |
Output is correct |
11 |
Correct |
6 ms |
6824 KB |
Output is correct |
12 |
Correct |
3 ms |
5608 KB |
Output is correct |
13 |
Correct |
3 ms |
5608 KB |
Output is correct |
14 |
Correct |
0 ms |
5604 KB |
Output is correct |
15 |
Correct |
3 ms |
5604 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Partially correct |
35 ms |
6256 KB |
Partially correct |
2 |
Partially correct |
35 ms |
6256 KB |
Partially correct |
3 |
Correct |
28 ms |
6256 KB |
Output is correct |
4 |
Correct |
22 ms |
6256 KB |
Output is correct |
5 |
Correct |
19 ms |
6572 KB |
Output is correct |
6 |
Partially correct |
15 ms |
6408 KB |
Partially correct |
7 |
Correct |
15 ms |
6364 KB |
Output is correct |
8 |
Correct |
12 ms |
6256 KB |
Output is correct |
9 |
Correct |
6 ms |
6296 KB |
Output is correct |
10 |
Correct |
15 ms |
6384 KB |
Output is correct |
11 |
Correct |
22 ms |
6384 KB |
Output is correct |
12 |
Correct |
16 ms |
6152 KB |
Output is correct |
13 |
Correct |
22 ms |
6152 KB |
Output is correct |
14 |
Correct |
18 ms |
6136 KB |
Output is correct |
15 |
Correct |
22 ms |
6256 KB |
Output is correct |
16 |
Partially correct |
22 ms |
6256 KB |
Partially correct |
17 |
Correct |
28 ms |
6256 KB |
Output is correct |
18 |
Correct |
22 ms |
6256 KB |
Output is correct |
19 |
Partially correct |
22 ms |
6256 KB |
Partially correct |
20 |
Incorrect |
18 ms |
6372 KB |
Output isn't correct |
21 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
28 ms |
6256 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |