#include <bits/stdc++.h>
#include "Joi.h"
using namespace std;
typedef long long ll;
typedef vector<int> vi;
#define rep(i , j , k) for(int i = j; i < (int)k; i++)
#define pb push_back
constexpr int N = 1e4 + 10;
int root = -1, len = -1;
int lvl[N], val[N];
vi adj[N];
bitset<N << 1> m1, m2;
void dfs0(int v, int a[], int b[]) {
m1[v] = true;
for (auto e : adj[v]) {
int u = v ^ a[e] ^ b[e];
if (!m1[u]) {
m2[e] = true;
dfs0(u, a, b);
}
}
}
void dfs1(int v, int par = -1) {
for (auto e : adj[v])
if (par ^ e) {
lvl[e] = lvl[v] + 1;
dfs1(e , v);
}
}
int cnt;
bool dfs2(int v , int dst , int par = -1) {
if (v == dst) {
m1[v] =true;
val[v] = ++cnt;
return true;
}
for (auto e :adj[v])
if (e ^ par && dfs2(e , dst , v)) {
m1[v] = true;
val[v] = ++cnt;
return true;
}
return false;
}
void dfs3(int v, int par = -1) {
if (!m1[v]) val[v] = ++cnt;
for (auto e :adj[v])
if (e ^ par)
dfs3(e , v);
}
inline void init(int n , int m , int a[], int b[]) {
rep(i , 0 , m)
{ adj[a[i]].pb(i);
adj[b[i]].pb(i);
}
dfs0(0, a, b);
rep(i , 0 , n) adj[i].clear();
rep(i , 0 , m) if(m2[i]) {
adj[a[i]].pb(b[i]);
adj[b[i]].pb(a[i]);
}
lvl[0] = 1;
dfs1(0);
root = max_element(lvl , lvl + n) - lvl;
lvl[root] = 1;
dfs1(root);
len = *max_element(lvl , lvl + n);
return;
}
void Joi(int n, int m, int a[] , int b[], ll x , int t) {
init(n , m , a , b);
if (len >= 60) {
rep(i , 0 , n)
MessageBoard(i , (x >> (lvl[i] % 60)) & 1);
}
else {
int root2 = max_element(lvl , lvl + n) - lvl;
m1.reset();
dfs2(root , root2);
dfs3(root);
rep(i , 0 , n)
MessageBoard(i , (x >> (val[i] - 1)) & 1);
}
return;
}
#include <bits/stdc++.h>
#include "Ioi.h"
using namespace std;
typedef long long ll;
typedef vector<int> vi;
#define rep(i , j , k) for(int i = j; i < (int)k; i++)
#define pb push_back
constexpr int N = 1e4 + 10;
int root = -1, len = -1;
int lvl[N], val[N];
vi adj[N];
bitset<N << 1> m1, m2;
void dfs0(int v, int a[], int b[]) {
m1[v] = true;
for (auto e : adj[v]) {
int u = v ^ a[e] ^ b[e];
if (!m1[u]) {
m2[e] = true;
dfs0(u, a, b);
}
}
}
void dfs1(int v, int par = -1) {
for (auto e : adj[v])
if (par ^ e) {
lvl[e] = lvl[v] + 1;
dfs1(e , v);
}
}
int cnt;
bool dfs2(int v , int dst , int par = -1) {
if (v == dst) {
m1[v] = true;
val[v] = ++cnt;
return true;
}
for (auto e :adj[v])
if (e ^ par && dfs2(e , dst , v)) {
m1[v] = true;
val[v] = ++cnt;
return true;
}
return false;
}
void dfs3(int v, int par = -1) {
if (!m1[v]) val[v] = ++cnt;
for (auto e :adj[v])
if (e ^ par)
dfs3(e , v);
}
inline void init(int n , int m , int a[], int b[]) {
rep(i , 0 , m)
{ adj[a[i]].pb(i);
adj[b[i]].pb(i);
}
dfs0(0, a, b);
rep(i , 0 , n) adj[i].clear();
rep(i , 0 , m) if(m2[i]) {
adj[a[i]].pb(b[i]);
adj[b[i]].pb(a[i]);
}
lvl[0] = 1;
dfs1(0);
root = max_element(lvl , lvl + n) - lvl;
lvl[root] = 1;
dfs1(root);
len = *max_element(lvl , lvl + n);
return;
}
ll res = 0;
void dfs4(int v, int &p , int &me, int par = -1) {
res |= (1ll * me) << (val[v] - 1);
for (auto e : adj[v])
if (e ^ par && !m1[e] && val[e] <= 60) {
me = Move(e);
p = e;
dfs4(e , p , me , v);
}
for (auto e :adj[v])
if (e ^ par && m1[e] && val[e] <= 60) {
me = Move(e);
p = e;
dfs4(e , p , me , v);
}
if (!m1[v]) {
me = Move(par);
p = par;
}
}
ll Ioi(int n, int m, int a[], int b[], int p ,int me, int t) {
init(n , m , a , b);
if (len >= 60) {
m1.reset();
dfs2(p , root);
if (lvl[p] >= 60) {
rep(i , 0 , 60) {
res |= (1ll * me) << (lvl[p] % 60);
for (auto e : adj[p])
if (m1[e]) {
me = Move(e);
m1[p] = false;
p = e;
break;
}
}
}
else {
while(true) {
bool flag = false;
for (auto e : adj[p])
if (m1[e]) {
me = Move(e);
m1[p] = false;
flag = true;
p = e;
break;
}
if (!flag) break;
}
int root2 = max_element(lvl , lvl + n) - lvl;
dfs2(p , root2);
rep(i , 0 , 60) {
res |= (1ll * me) << (lvl[p] % 60);
for (auto e : adj[p])
if (m1[e]) {
me = Move(e);
m1[p] = false;
p = e;
break;
}
}
}
return res;
}
////////////////////////////////////////
int root2 = max_element(lvl , lvl + n) - lvl;
m1.reset();
dfs2(p ,root);
while(true) {
bool flag = false;
for (auto e : adj[p])
if (m1[e]) {
me = Move(e);
m1[p] = false;
flag = true;
p = e;
break;
}
if (!flag) break;
}
cnt = 0;
m1.reset();
dfs2(root , root2);
dfs3(root);
dfs4(root, p , me);
return res;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
1380 KB |
Output is correct |
2 |
Correct |
5 ms |
1380 KB |
Output is correct |
3 |
Correct |
4 ms |
1372 KB |
Output is correct |
4 |
Correct |
4 ms |
1512 KB |
Output is correct |
5 |
Correct |
4 ms |
1260 KB |
Output is correct |
6 |
Correct |
4 ms |
1152 KB |
Output is correct |
7 |
Correct |
4 ms |
1536 KB |
Output is correct |
8 |
Correct |
4 ms |
1284 KB |
Output is correct |
9 |
Correct |
4 ms |
1412 KB |
Output is correct |
10 |
Correct |
4 ms |
1152 KB |
Output is correct |
11 |
Correct |
7 ms |
1652 KB |
Output is correct |
12 |
Correct |
4 ms |
1152 KB |
Output is correct |
13 |
Correct |
4 ms |
1292 KB |
Output is correct |
14 |
Correct |
5 ms |
1292 KB |
Output is correct |
15 |
Correct |
4 ms |
1372 KB |
Output is correct |
16 |
Correct |
4 ms |
1292 KB |
Output is correct |
17 |
Correct |
4 ms |
1412 KB |
Output is correct |
18 |
Correct |
2 ms |
1412 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
30 ms |
4316 KB |
Output is correct |
2 |
Correct |
31 ms |
4180 KB |
Output is correct |
3 |
Correct |
30 ms |
4332 KB |
Output is correct |
4 |
Correct |
20 ms |
2852 KB |
Output is correct |
5 |
Correct |
20 ms |
3648 KB |
Output is correct |
6 |
Correct |
19 ms |
3136 KB |
Output is correct |
7 |
Correct |
19 ms |
3144 KB |
Output is correct |
8 |
Correct |
20 ms |
3272 KB |
Output is correct |
9 |
Correct |
19 ms |
3160 KB |
Output is correct |
10 |
Correct |
15 ms |
2888 KB |
Output is correct |
11 |
Correct |
16 ms |
2880 KB |
Output is correct |
12 |
Correct |
17 ms |
2656 KB |
Output is correct |
13 |
Correct |
17 ms |
2608 KB |
Output is correct |
14 |
Correct |
18 ms |
2816 KB |
Output is correct |
15 |
Correct |
20 ms |
2856 KB |
Output is correct |
16 |
Correct |
22 ms |
2888 KB |
Output is correct |
17 |
Correct |
20 ms |
2852 KB |
Output is correct |
18 |
Correct |
19 ms |
2888 KB |
Output is correct |
19 |
Correct |
22 ms |
2888 KB |
Output is correct |
20 |
Correct |
15 ms |
3488 KB |
Output is correct |
21 |
Correct |
16 ms |
3400 KB |
Output is correct |
22 |
Correct |
20 ms |
3220 KB |
Output is correct |
23 |
Correct |
20 ms |
3136 KB |
Output is correct |
24 |
Correct |
19 ms |
3336 KB |
Output is correct |
25 |
Correct |
20 ms |
3136 KB |
Output is correct |
26 |
Correct |
20 ms |
3164 KB |
Output is correct |
27 |
Correct |
15 ms |
3264 KB |
Output is correct |
28 |
Correct |
19 ms |
3372 KB |
Output is correct |
29 |
Correct |
19 ms |
3128 KB |
Output is correct |
30 |
Correct |
17 ms |
3128 KB |
Output is correct |
31 |
Correct |
4 ms |
1380 KB |
Output is correct |
32 |
Correct |
4 ms |
1152 KB |
Output is correct |
33 |
Correct |
4 ms |
1412 KB |
Output is correct |
34 |
Correct |
4 ms |
1152 KB |
Output is correct |
35 |
Correct |
4 ms |
1380 KB |
Output is correct |
36 |
Correct |
4 ms |
1416 KB |
Output is correct |
37 |
Correct |
4 ms |
1288 KB |
Output is correct |
38 |
Correct |
4 ms |
1416 KB |
Output is correct |
39 |
Correct |
4 ms |
1152 KB |
Output is correct |
40 |
Correct |
5 ms |
1416 KB |
Output is correct |
41 |
Correct |
4 ms |
1408 KB |
Output is correct |
42 |
Correct |
4 ms |
1404 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
1280 KB |
Output is correct |
2 |
Correct |
7 ms |
1660 KB |
Output is correct |
3 |
Correct |
4 ms |
1152 KB |
Output is correct |
4 |
Correct |
6 ms |
1700 KB |
Output is correct |
5 |
Correct |
6 ms |
1740 KB |
Output is correct |
6 |
Correct |
7 ms |
1744 KB |
Output is correct |
7 |
Correct |
6 ms |
1692 KB |
Output is correct |
8 |
Correct |
5 ms |
1692 KB |
Output is correct |
9 |
Correct |
15 ms |
3912 KB |
Output is correct |
10 |
Correct |
15 ms |
3912 KB |
Output is correct |
11 |
Correct |
15 ms |
4080 KB |
Output is correct |
12 |
Correct |
4 ms |
1408 KB |
Output is correct |
13 |
Correct |
4 ms |
1288 KB |
Output is correct |
14 |
Correct |
4 ms |
1288 KB |
Output is correct |
15 |
Correct |
4 ms |
1416 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
31 ms |
4180 KB |
Output is correct |
2 |
Correct |
30 ms |
4444 KB |
Output is correct |
3 |
Correct |
30 ms |
4332 KB |
Output is correct |
4 |
Correct |
20 ms |
2888 KB |
Output is correct |
5 |
Correct |
20 ms |
3776 KB |
Output is correct |
6 |
Correct |
20 ms |
3316 KB |
Output is correct |
7 |
Correct |
20 ms |
3228 KB |
Output is correct |
8 |
Correct |
20 ms |
3272 KB |
Output is correct |
9 |
Correct |
19 ms |
3136 KB |
Output is correct |
10 |
Correct |
16 ms |
2888 KB |
Output is correct |
11 |
Correct |
17 ms |
2880 KB |
Output is correct |
12 |
Correct |
18 ms |
2608 KB |
Output is correct |
13 |
Correct |
17 ms |
2608 KB |
Output is correct |
14 |
Correct |
19 ms |
2876 KB |
Output is correct |
15 |
Correct |
22 ms |
2856 KB |
Output is correct |
16 |
Correct |
20 ms |
2624 KB |
Output is correct |
17 |
Correct |
20 ms |
2888 KB |
Output is correct |
18 |
Correct |
20 ms |
2976 KB |
Output is correct |
19 |
Correct |
20 ms |
2624 KB |
Output is correct |
20 |
Correct |
13 ms |
3480 KB |
Output is correct |
21 |
Correct |
14 ms |
3264 KB |
Output is correct |
22 |
Correct |
19 ms |
3264 KB |
Output is correct |
23 |
Correct |
20 ms |
3264 KB |
Output is correct |
24 |
Correct |
20 ms |
3264 KB |
Output is correct |
25 |
Correct |
19 ms |
3264 KB |
Output is correct |
26 |
Correct |
19 ms |
3308 KB |
Output is correct |
27 |
Correct |
25 ms |
3280 KB |
Output is correct |
28 |
Correct |
20 ms |
3264 KB |
Output is correct |
29 |
Correct |
19 ms |
3148 KB |
Output is correct |
30 |
Correct |
19 ms |
3128 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
31 ms |
4180 KB |
Output is correct |
2 |
Correct |
33 ms |
4296 KB |
Output is correct |
3 |
Correct |
28 ms |
4144 KB |
Output is correct |
4 |
Correct |
20 ms |
3004 KB |
Output is correct |
5 |
Correct |
20 ms |
3824 KB |
Output is correct |
6 |
Correct |
20 ms |
3220 KB |
Output is correct |
7 |
Correct |
32 ms |
3248 KB |
Output is correct |
8 |
Correct |
20 ms |
3340 KB |
Output is correct |
9 |
Correct |
20 ms |
3128 KB |
Output is correct |
10 |
Correct |
18 ms |
2924 KB |
Output is correct |
11 |
Correct |
17 ms |
2948 KB |
Output is correct |
12 |
Correct |
18 ms |
2648 KB |
Output is correct |
13 |
Correct |
18 ms |
2744 KB |
Output is correct |
14 |
Correct |
19 ms |
2624 KB |
Output is correct |
15 |
Correct |
24 ms |
2752 KB |
Output is correct |
16 |
Correct |
20 ms |
2976 KB |
Output is correct |
17 |
Correct |
19 ms |
3000 KB |
Output is correct |
18 |
Correct |
20 ms |
2880 KB |
Output is correct |
19 |
Correct |
19 ms |
2816 KB |
Output is correct |
20 |
Correct |
15 ms |
3508 KB |
Output is correct |
21 |
Correct |
14 ms |
3392 KB |
Output is correct |
22 |
Correct |
19 ms |
3144 KB |
Output is correct |
23 |
Correct |
20 ms |
3452 KB |
Output is correct |
24 |
Correct |
19 ms |
3336 KB |
Output is correct |
25 |
Correct |
19 ms |
3136 KB |
Output is correct |
26 |
Correct |
19 ms |
3264 KB |
Output is correct |
27 |
Correct |
19 ms |
3400 KB |
Output is correct |
28 |
Correct |
20 ms |
3400 KB |
Output is correct |
29 |
Correct |
17 ms |
3128 KB |
Output is correct |
30 |
Correct |
19 ms |
3164 KB |
Output is correct |
31 |
Correct |
4 ms |
1380 KB |
Output is correct |
32 |
Correct |
5 ms |
1280 KB |
Output is correct |
33 |
Correct |
4 ms |
1200 KB |
Output is correct |
34 |
Correct |
4 ms |
1152 KB |
Output is correct |
35 |
Correct |
4 ms |
1284 KB |
Output is correct |
36 |
Correct |
4 ms |
1288 KB |
Output is correct |
37 |
Correct |
4 ms |
1408 KB |
Output is correct |
38 |
Correct |
4 ms |
1380 KB |
Output is correct |
39 |
Correct |
4 ms |
1288 KB |
Output is correct |
40 |
Correct |
4 ms |
1288 KB |
Output is correct |
41 |
Correct |
4 ms |
1368 KB |
Output is correct |
42 |
Correct |
4 ms |
1156 KB |
Output is correct |