#include "Joi.h"
#include <bits/stdc++.h>
using i64 = long long;
using namespace std;
namespace joi {
const int MAX_BIT = 60;
int n;
vector<vector<int>> e, adj;
vector<bool> vis;
void dfs(int u) {
vis[u] = true;
for (int v : adj[u]) {
if (!vis[v]) {
e[u].push_back(v);
e[v].push_back(u);
dfs(v);
}
}
}
int cnt = 0;
set<int> s;
vector<set<int>> f;
vector<int> val(n);
void find(int u, int p) {
val[u] = cnt++;
if (cnt == MAX_BIT) {
return;
}
for (int v : e[u]) {
if (v != p) {
f[u].insert(v);
f[v].insert(u);
find(v, u);
if (cnt == MAX_BIT)
return;
}
}
}
void mark(int u, int p) {
bool in = false, op1 = false, op2 = false;
int x = -1, to = -1;
if (val[u] == -1) {
in = true;
auto t = s.begin();
if (*t == p) t++;
x = *t;
to = *f[x].begin();
s.erase(x);
f[x].erase(to);
f[to].erase(x);
if (f[to].size() == 1) {
op1 = true;
s.insert(to);
}
if (f[p].size() == 1) {
op2 = true;
s.erase(p);
}
f[p].insert(u);
f[u].insert(p);
s.insert(u);
val[u] = val[x];
}
for (int v : e[u]) {
if (v != p) {
mark(v, u);
}
}
if (in) {
s.erase(u);
f[p].erase(u);
f[u].erase(p);
if (op2) {
s.insert(p);
}
if (op1) {
s.erase(to);
}
f[x].insert(to);
f[to].insert(x);
s.insert(x);
}
}
};
using namespace joi;
void Joi(int N, int M, int A[], int B[], long long X, int T) {
n = N;
adj.resize(n);
e.resize(n);
for (int i = 0; i < M; i++) {
adj[A[i]].push_back(B[i]);
adj[B[i]].push_back(A[i]);
}
vis.assign(n, 0);
dfs(0);
f.resize(n);
val.resize(n, -1);
find(0, -1);
for (int i = 0; i < n; i++) {
if (f[i].size() == 1) {
s.insert(i);
}
}
mark(0, -1);
for (int i = 0; i < n; i++) {
assert(val[i] != -1);
MessageBoard(i, X >> val[i] & 1);
}
}
#include "Ioi.h"
#include <bits/stdc++.h>
using i64 = long long;
using namespace std;
namespace ioi {
const int MAX_BIT = 60;
int n;
vector<vector<int>> e, adj;
vector<bool> vis;
void dfs(int u) {
vis[u] = true;
for (int v : adj[u]) {
if (!vis[v]) {
e[u].push_back(v);
e[v].push_back(u);
dfs(v);
}
}
}
int cnt = 0;
set<int> s;
vector<set<int>> f;
vector<int> val(n);
void find(int u, int p) {
val[u] = cnt++;
if (cnt == MAX_BIT) {
return;
}
for (int v : e[u]) {
if (v != p) {
f[u].insert(v);
f[v].insert(u);
find(v, u);
if (cnt == MAX_BIT)
return;
}
}
}
void mark(int u, int p) {
bool in = false, op1 = false, op2 = false;
int x = -1, to = -1;
if (val[u] == -1) {
in = true;
auto t = s.begin();
if (*t == p) t++;
x = *t;
to = *f[x].begin();
s.erase(x);
f[x].erase(to);
f[to].erase(x);
if (f[to].size() == 1) {
op1 = true;
s.insert(to);
}
if (f[p].size() == 1) {
op2 = true;
s.erase(p);
}
f[p].insert(u);
f[u].insert(p);
s.insert(u);
val[u] = val[x];
}
for (int v : e[u]) {
if (v != p) {
mark(v, u);
}
}
if (in) {
s.erase(u);
f[p].erase(u);
f[u].erase(p);
if (op2) {
s.insert(p);
}
if (op1) {
s.erase(to);
}
f[x].insert(to);
f[to].insert(x);
s.insert(x);
}
}
vector<bool> h(MAX_BIT);
i64 ans = 0;
void get(int u) {
for (int v : e[u]) {
if (!h[val[v]]) {
int x = Move(v);
ans |= (1LL * x) << val[v];
h[val[v]] = true;
get(v);
Move(u);
}
}
}
};
using namespace ioi;
long long Ioi(int N, int M, int A[], int B[], int u, int V, int T) {
n = N;
adj.resize(n);
e.resize(n);
for (int i = 0; i < M; i++) {
adj[A[i]].push_back(B[i]);
adj[B[i]].push_back(A[i]);
}
vis.assign(n, 0);
dfs(0);
f.resize(n);
val.resize(n, -1);
find(0, -1);
for (int i = 0; i < n; i++) {
if (f[i].size() == 1) {
s.insert(i);
}
}
mark(0, -1);
h[val[u]] = 0;
ans = (1LL * V) << val[u];
get(u);
return ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
556 KB |
Output is correct |
2 |
Correct |
2 ms |
752 KB |
Output is correct |
3 |
Correct |
2 ms |
756 KB |
Output is correct |
4 |
Correct |
1 ms |
764 KB |
Output is correct |
5 |
Correct |
2 ms |
716 KB |
Output is correct |
6 |
Correct |
1 ms |
764 KB |
Output is correct |
7 |
Correct |
2 ms |
768 KB |
Output is correct |
8 |
Correct |
2 ms |
696 KB |
Output is correct |
9 |
Correct |
2 ms |
764 KB |
Output is correct |
10 |
Correct |
1 ms |
724 KB |
Output is correct |
11 |
Correct |
4 ms |
968 KB |
Output is correct |
12 |
Correct |
1 ms |
752 KB |
Output is correct |
13 |
Correct |
2 ms |
768 KB |
Output is correct |
14 |
Correct |
2 ms |
768 KB |
Output is correct |
15 |
Correct |
2 ms |
768 KB |
Output is correct |
16 |
Correct |
2 ms |
768 KB |
Output is correct |
17 |
Correct |
2 ms |
728 KB |
Output is correct |
18 |
Correct |
2 ms |
768 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
38 ms |
6716 KB |
Output is correct |
2 |
Correct |
38 ms |
6788 KB |
Output is correct |
3 |
Correct |
32 ms |
6812 KB |
Output is correct |
4 |
Correct |
26 ms |
4940 KB |
Output is correct |
5 |
Correct |
28 ms |
5632 KB |
Output is correct |
6 |
Correct |
24 ms |
5448 KB |
Output is correct |
7 |
Correct |
29 ms |
5296 KB |
Output is correct |
8 |
Correct |
23 ms |
5604 KB |
Output is correct |
9 |
Correct |
20 ms |
5628 KB |
Output is correct |
10 |
Correct |
20 ms |
4904 KB |
Output is correct |
11 |
Correct |
20 ms |
4976 KB |
Output is correct |
12 |
Correct |
23 ms |
4360 KB |
Output is correct |
13 |
Correct |
24 ms |
4432 KB |
Output is correct |
14 |
Correct |
29 ms |
4588 KB |
Output is correct |
15 |
Correct |
26 ms |
4880 KB |
Output is correct |
16 |
Correct |
24 ms |
4904 KB |
Output is correct |
17 |
Correct |
24 ms |
4876 KB |
Output is correct |
18 |
Correct |
26 ms |
4876 KB |
Output is correct |
19 |
Correct |
27 ms |
4848 KB |
Output is correct |
20 |
Correct |
26 ms |
5780 KB |
Output is correct |
21 |
Correct |
22 ms |
5640 KB |
Output is correct |
22 |
Correct |
22 ms |
5276 KB |
Output is correct |
23 |
Correct |
23 ms |
5524 KB |
Output is correct |
24 |
Correct |
23 ms |
5460 KB |
Output is correct |
25 |
Correct |
26 ms |
5428 KB |
Output is correct |
26 |
Correct |
24 ms |
5492 KB |
Output is correct |
27 |
Correct |
25 ms |
5472 KB |
Output is correct |
28 |
Correct |
22 ms |
5672 KB |
Output is correct |
29 |
Correct |
19 ms |
5048 KB |
Output is correct |
30 |
Correct |
20 ms |
5140 KB |
Output is correct |
31 |
Correct |
2 ms |
756 KB |
Output is correct |
32 |
Correct |
2 ms |
752 KB |
Output is correct |
33 |
Correct |
2 ms |
760 KB |
Output is correct |
34 |
Correct |
2 ms |
764 KB |
Output is correct |
35 |
Correct |
2 ms |
636 KB |
Output is correct |
36 |
Correct |
2 ms |
752 KB |
Output is correct |
37 |
Correct |
1 ms |
496 KB |
Output is correct |
38 |
Correct |
1 ms |
492 KB |
Output is correct |
39 |
Correct |
2 ms |
624 KB |
Output is correct |
40 |
Correct |
1 ms |
764 KB |
Output is correct |
41 |
Correct |
1 ms |
716 KB |
Output is correct |
42 |
Correct |
2 ms |
636 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
752 KB |
Output is correct |
2 |
Correct |
2 ms |
704 KB |
Output is correct |
3 |
Correct |
2 ms |
768 KB |
Output is correct |
4 |
Correct |
4 ms |
1548 KB |
Output is correct |
5 |
Correct |
5 ms |
1552 KB |
Output is correct |
6 |
Correct |
4 ms |
1700 KB |
Output is correct |
7 |
Correct |
4 ms |
1512 KB |
Output is correct |
8 |
Correct |
4 ms |
1572 KB |
Output is correct |
9 |
Correct |
18 ms |
6668 KB |
Output is correct |
10 |
Correct |
19 ms |
6696 KB |
Output is correct |
11 |
Correct |
19 ms |
6692 KB |
Output is correct |
12 |
Correct |
2 ms |
596 KB |
Output is correct |
13 |
Correct |
2 ms |
760 KB |
Output is correct |
14 |
Correct |
1 ms |
708 KB |
Output is correct |
15 |
Correct |
1 ms |
624 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
32 ms |
6764 KB |
Output is correct |
2 |
Correct |
30 ms |
6892 KB |
Output is correct |
3 |
Correct |
31 ms |
6792 KB |
Output is correct |
4 |
Correct |
30 ms |
4896 KB |
Output is correct |
5 |
Correct |
24 ms |
6160 KB |
Output is correct |
6 |
Correct |
23 ms |
5600 KB |
Output is correct |
7 |
Correct |
23 ms |
5532 KB |
Output is correct |
8 |
Correct |
23 ms |
5168 KB |
Output is correct |
9 |
Correct |
27 ms |
5308 KB |
Output is correct |
10 |
Correct |
25 ms |
4888 KB |
Output is correct |
11 |
Correct |
20 ms |
4944 KB |
Output is correct |
12 |
Correct |
25 ms |
4392 KB |
Output is correct |
13 |
Correct |
25 ms |
4424 KB |
Output is correct |
14 |
Correct |
25 ms |
4632 KB |
Output is correct |
15 |
Correct |
24 ms |
4864 KB |
Output is correct |
16 |
Correct |
28 ms |
4844 KB |
Output is correct |
17 |
Correct |
26 ms |
4936 KB |
Output is correct |
18 |
Correct |
25 ms |
4896 KB |
Output is correct |
19 |
Correct |
24 ms |
4888 KB |
Output is correct |
20 |
Correct |
19 ms |
5756 KB |
Output is correct |
21 |
Correct |
19 ms |
5760 KB |
Output is correct |
22 |
Correct |
26 ms |
5448 KB |
Output is correct |
23 |
Correct |
24 ms |
5408 KB |
Output is correct |
24 |
Correct |
23 ms |
5380 KB |
Output is correct |
25 |
Correct |
31 ms |
5496 KB |
Output is correct |
26 |
Correct |
26 ms |
5436 KB |
Output is correct |
27 |
Correct |
23 ms |
5664 KB |
Output is correct |
28 |
Correct |
23 ms |
5420 KB |
Output is correct |
29 |
Correct |
22 ms |
5104 KB |
Output is correct |
30 |
Correct |
33 ms |
5376 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
36 ms |
6788 KB |
Output is correct |
2 |
Correct |
38 ms |
6848 KB |
Output is correct |
3 |
Correct |
30 ms |
6728 KB |
Output is correct |
4 |
Correct |
23 ms |
4880 KB |
Output is correct |
5 |
Correct |
28 ms |
6404 KB |
Output is correct |
6 |
Correct |
23 ms |
5384 KB |
Output is correct |
7 |
Correct |
23 ms |
5272 KB |
Output is correct |
8 |
Correct |
24 ms |
5572 KB |
Output is correct |
9 |
Correct |
24 ms |
5372 KB |
Output is correct |
10 |
Correct |
23 ms |
4928 KB |
Output is correct |
11 |
Correct |
22 ms |
4972 KB |
Output is correct |
12 |
Correct |
23 ms |
4324 KB |
Output is correct |
13 |
Correct |
25 ms |
4368 KB |
Output is correct |
14 |
Correct |
31 ms |
4592 KB |
Output is correct |
15 |
Correct |
25 ms |
4904 KB |
Output is correct |
16 |
Correct |
26 ms |
4856 KB |
Output is correct |
17 |
Correct |
34 ms |
4844 KB |
Output is correct |
18 |
Correct |
24 ms |
4876 KB |
Output is correct |
19 |
Correct |
24 ms |
4872 KB |
Output is correct |
20 |
Correct |
23 ms |
5712 KB |
Output is correct |
21 |
Correct |
19 ms |
5676 KB |
Output is correct |
22 |
Correct |
22 ms |
5520 KB |
Output is correct |
23 |
Correct |
23 ms |
5336 KB |
Output is correct |
24 |
Correct |
22 ms |
5408 KB |
Output is correct |
25 |
Correct |
25 ms |
5408 KB |
Output is correct |
26 |
Correct |
22 ms |
5260 KB |
Output is correct |
27 |
Correct |
20 ms |
5548 KB |
Output is correct |
28 |
Correct |
25 ms |
5660 KB |
Output is correct |
29 |
Correct |
20 ms |
5236 KB |
Output is correct |
30 |
Correct |
27 ms |
5372 KB |
Output is correct |
31 |
Correct |
1 ms |
760 KB |
Output is correct |
32 |
Correct |
2 ms |
764 KB |
Output is correct |
33 |
Correct |
2 ms |
768 KB |
Output is correct |
34 |
Correct |
2 ms |
752 KB |
Output is correct |
35 |
Correct |
1 ms |
752 KB |
Output is correct |
36 |
Correct |
1 ms |
624 KB |
Output is correct |
37 |
Correct |
1 ms |
720 KB |
Output is correct |
38 |
Correct |
2 ms |
732 KB |
Output is correct |
39 |
Correct |
1 ms |
628 KB |
Output is correct |
40 |
Correct |
2 ms |
696 KB |
Output is correct |
41 |
Correct |
2 ms |
764 KB |
Output is correct |
42 |
Correct |
1 ms |
756 KB |
Output is correct |