#include <bits/stdc++.h>
#define fr(i, n, m) for(int i = (n); i < (m); i ++)
#define pb push_back
#define st first
#define nd second
#define pq priority_queue
#define all(x) begin(x), end(x)
#include <time.h>
#include <cmath>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
const int i_inf = 1e9;
const ll inf = 1e17;
const ll mod = 1000000007;
const ld eps = 1e-13;
const ld pi = 3.14159265359;
mt19937 _rand(time(NULL));
clock_t timer = clock();
const int mxn = 1e5;
#include "Joi.h"
/*int VAL[mxn];
void MessageBoard(int u, int val){
VAL[u] = val;
return;
}*/
int n, m;
int a[mxn], b[mxn];
bool vis[mxn];
vector<int> g[mxn];
int itopos[mxn];
int temp_p = 0;
int depth[mxn];
int mx_depth[mxn];
int best_child[mxn];
vector<int> G[mxn];
void dfs(int u){
itopos[u] = temp_p++;
vis[u] = true;
mx_depth[u] = depth[u];
best_child[u] = u;
for(auto e : g[u]){
if(vis[e]) continue;
depth[e] = depth[u] + 1;
G[u].pb(e);
dfs(e);
if(mx_depth[u] < mx_depth[e]){
mx_depth[u] = mx_depth[e];
best_child[u] = e;
}
}
}
int REM;
int pos_to_mark;
ll x;
void dfs2(int u, int flag){
if(flag == 0){
if(x&(1LL<<pos_to_mark)) MessageBoard(u, 1);
else MessageBoard(u, 0);
++pos_to_mark;
}
else{
if(REM > 0){
if(x&(1LL<<pos_to_mark)) MessageBoard(u, 1);
else MessageBoard(u, 0);
++pos_to_mark;
--REM;
}
else{
MessageBoard(u, 0);
}
}
if(flag == 1){
for(auto e : G[u]){
dfs2(e, 1);
}
}
else{
for(auto e : G[u]){
if(e == best_child[u]) continue;
dfs2(e, 1);
}
if(u != best_child[u]) dfs2(best_child[u], 0);
}
}
void Joi(int N, int M, int A[], int B[], long long X, int T) {
n = N, m = M, x = X;
fr(i, 0, m) a[i] = A[i], b[i] = B[i];
fr(i, 0, m){
g[a[i]].pb(b[i]);
g[b[i]].pb(a[i]);
}
dfs(0);
int mxd = 0;
fr(i, 0, n) mxd = max(mxd, depth[i]);
if(mxd < 59){
REM = 60 - (mx_depth[0]+1);
dfs2(0, 0);
/*fr(i, 0, n){
if(X&(1LL<<(itopos[i]%60))) MessageBoard(i,1);
else MessageBoard(i,0);
}*/
}
else{
fr(i, 0, n){
if(X&(1LL<<(depth[i]%60)))MessageBoard(i,1);
else MessageBoard(i,0);
}
}
}
#include <bits/stdc++.h>
#define fr(i, n, m) for(int i = (n); i < (m); i ++)
#define pb push_back
#define st first
#define nd second
#define pq priority_queue
#define all(x) begin(x), end(x)
#include <time.h>
#include <cmath>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
const int i_inf = 1e9;
const ll inf = 1e17;
const ll mod = 1000000007;
const ld eps = 1e-13;
const ld pi = 3.14159265359;
mt19937 _rand(time(NULL));
clock_t timer = clock();
const int mxn = 1e5;
#include "Ioi.h"
/*
int mark[60] = {1,1,0,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
int Move(int u){
cout<<u<<endl;
return mark[u];
}*/
int n, m;
int a[mxn], b[mxn];
bool vis[mxn];
vector<int> g[mxn];
int postoi[mxn];
int temp_p = 0;
vector<int> v;
int val[mxn];
int parent[mxn];
int depth[mxn];
int mx_depth[mxn];
int best_child[mxn];
vector<int> G[mxn];
void dfs(int u, int p){
parent[u] = p;
postoi[temp_p] = u;
++temp_p;
vis[u] = true;
mx_depth[u] = depth[u];
best_child[u] = u;
for(auto e : g[u]){
if(vis[e]) continue;
G[u].pb(e);
depth[e] = depth[u] + 1;
dfs(e, u);
if(mx_depth[e] > mx_depth[u]){
mx_depth[u] = mx_depth[e];
best_child[u] = e;
}
}
}
/*
int loc_pos;
void dfs2(int u, int p, int tv){
loc_pos ++;
val[u] = tv;
vis[u] = true;
if(loc_pos == 60) return;
for(auto e : g[u]){
if(vis[e]) continue;
dfs2(e, u, Move(e));
if(loc_pos == 60) return;
}
if(u != p) Move(parent[u]);
}*/
int REM;
int pos_to_mark;
ll x;
void dfs2(int u, int flag, int tv){
x |= (1LL<<pos_to_mark)*tv;
++pos_to_mark;
if(flag == 1){
--REM;
if(REM == 0){
Move(parent[u]);
return;
}
for(auto e : G[u]){
dfs2(e, 1, Move(e));
if(REM == 0) break;
}
Move(parent[u]);
}
else{
for(auto e : G[u]){
if(e == best_child[u]) continue;
if(REM == 0) break;
dfs2(e, 1, Move(e));
}
if(u != best_child[u]) dfs2(best_child[u], 0, Move(best_child[u]));
return;
}
}
long long Ioi(int N, int M, int A[], int B[], int P, int V, int T) {
n = N, m = M;
fr(i, 0, m) a[i] = A[i], b[i] = B[i];
fr(i, 0, m){
g[a[i]].pb(b[i]);
g[b[i]].pb(a[i]);
}
dfs(0, 0);
if(mx_depth[0] < 59){
while(P != 0) V = Move(parent[P]), P = parent[P];
REM = 60 - (mx_depth[0]+1);
dfs2(0, 0, V);
/*while(P != 0) V = Move(parent[P]), P = parent[P];
val[0] = V;
memset(vis, false, sizeof(vis));
dfs2(0, 0, V);
ll X = 0;
fr(i, 0, 60){
X |= (1LL<<i)*val[postoi[i]];
}*/
return x;
}
else{
while(depth[P]%60 != 0) V = Move(parent[P]), P = parent[P];
ll X = 0;
if(mx_depth[P]-depth[P]<59){
fr(i, 0, 60){
V = Move(parent[P]);
P = parent[P];
X |= (1LL<<(59-i))*V;
}
}
else{
X |= (1LL << 0)*V;
fr(i, 1, 60){
V = Move(best_child[P]);
P = best_child[P];
X |= (1LL<<i)*V;
}
}
return X;
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
10364 KB |
Output is correct |
2 |
Correct |
7 ms |
10492 KB |
Output is correct |
3 |
Correct |
7 ms |
10472 KB |
Output is correct |
4 |
Correct |
7 ms |
10488 KB |
Output is correct |
5 |
Correct |
6 ms |
10488 KB |
Output is correct |
6 |
Correct |
6 ms |
10248 KB |
Output is correct |
7 |
Correct |
8 ms |
10464 KB |
Output is correct |
8 |
Correct |
7 ms |
10472 KB |
Output is correct |
9 |
Correct |
8 ms |
10384 KB |
Output is correct |
10 |
Correct |
6 ms |
10376 KB |
Output is correct |
11 |
Correct |
11 ms |
10732 KB |
Output is correct |
12 |
Correct |
7 ms |
10488 KB |
Output is correct |
13 |
Correct |
8 ms |
10256 KB |
Output is correct |
14 |
Correct |
7 ms |
10428 KB |
Output is correct |
15 |
Correct |
7 ms |
10472 KB |
Output is correct |
16 |
Correct |
7 ms |
10384 KB |
Output is correct |
17 |
Correct |
6 ms |
10256 KB |
Output is correct |
18 |
Correct |
7 ms |
10472 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
35 ms |
14360 KB |
Output is correct |
2 |
Correct |
35 ms |
14492 KB |
Output is correct |
3 |
Correct |
34 ms |
14308 KB |
Output is correct |
4 |
Correct |
23 ms |
12524 KB |
Output is correct |
5 |
Correct |
25 ms |
13612 KB |
Output is correct |
6 |
Correct |
24 ms |
13228 KB |
Output is correct |
7 |
Correct |
23 ms |
13228 KB |
Output is correct |
8 |
Correct |
24 ms |
13416 KB |
Output is correct |
9 |
Correct |
28 ms |
13228 KB |
Output is correct |
10 |
Correct |
20 ms |
12812 KB |
Output is correct |
11 |
Correct |
22 ms |
12816 KB |
Output is correct |
12 |
Correct |
20 ms |
12488 KB |
Output is correct |
13 |
Correct |
22 ms |
12596 KB |
Output is correct |
14 |
Correct |
24 ms |
12828 KB |
Output is correct |
15 |
Correct |
26 ms |
12844 KB |
Output is correct |
16 |
Correct |
27 ms |
13192 KB |
Output is correct |
17 |
Correct |
26 ms |
12760 KB |
Output is correct |
18 |
Correct |
25 ms |
12760 KB |
Output is correct |
19 |
Correct |
24 ms |
12764 KB |
Output is correct |
20 |
Correct |
20 ms |
13516 KB |
Output is correct |
21 |
Correct |
20 ms |
13356 KB |
Output is correct |
22 |
Correct |
23 ms |
12972 KB |
Output is correct |
23 |
Correct |
28 ms |
13324 KB |
Output is correct |
24 |
Correct |
23 ms |
12972 KB |
Output is correct |
25 |
Correct |
25 ms |
13360 KB |
Output is correct |
26 |
Correct |
27 ms |
13228 KB |
Output is correct |
27 |
Correct |
30 ms |
13316 KB |
Output is correct |
28 |
Correct |
30 ms |
13432 KB |
Output is correct |
29 |
Correct |
20 ms |
12948 KB |
Output is correct |
30 |
Correct |
22 ms |
13140 KB |
Output is correct |
31 |
Correct |
8 ms |
10484 KB |
Output is correct |
32 |
Correct |
8 ms |
10484 KB |
Output is correct |
33 |
Correct |
6 ms |
10256 KB |
Output is correct |
34 |
Correct |
6 ms |
10504 KB |
Output is correct |
35 |
Correct |
6 ms |
10492 KB |
Output is correct |
36 |
Correct |
6 ms |
10492 KB |
Output is correct |
37 |
Correct |
7 ms |
10248 KB |
Output is correct |
38 |
Correct |
6 ms |
10500 KB |
Output is correct |
39 |
Correct |
8 ms |
10248 KB |
Output is correct |
40 |
Correct |
7 ms |
10504 KB |
Output is correct |
41 |
Correct |
6 ms |
10484 KB |
Output is correct |
42 |
Correct |
7 ms |
10500 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
10404 KB |
Output is correct |
2 |
Correct |
6 ms |
10488 KB |
Output is correct |
3 |
Correct |
7 ms |
10372 KB |
Output is correct |
4 |
Correct |
9 ms |
10788 KB |
Output is correct |
5 |
Correct |
8 ms |
10916 KB |
Output is correct |
6 |
Correct |
8 ms |
11008 KB |
Output is correct |
7 |
Correct |
9 ms |
11004 KB |
Output is correct |
8 |
Correct |
10 ms |
11012 KB |
Output is correct |
9 |
Correct |
20 ms |
14156 KB |
Output is correct |
10 |
Correct |
20 ms |
14156 KB |
Output is correct |
11 |
Correct |
19 ms |
14028 KB |
Output is correct |
12 |
Correct |
7 ms |
10620 KB |
Output is correct |
13 |
Correct |
6 ms |
10372 KB |
Output is correct |
14 |
Correct |
6 ms |
10244 KB |
Output is correct |
15 |
Correct |
6 ms |
10628 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
35 ms |
14492 KB |
Output is correct |
2 |
Correct |
36 ms |
14436 KB |
Output is correct |
3 |
Correct |
36 ms |
14364 KB |
Output is correct |
4 |
Correct |
24 ms |
12492 KB |
Output is correct |
5 |
Correct |
26 ms |
13868 KB |
Output is correct |
6 |
Correct |
25 ms |
13408 KB |
Output is correct |
7 |
Correct |
26 ms |
13228 KB |
Output is correct |
8 |
Correct |
24 ms |
13132 KB |
Output is correct |
9 |
Correct |
25 ms |
13100 KB |
Output is correct |
10 |
Correct |
20 ms |
12808 KB |
Output is correct |
11 |
Correct |
25 ms |
12836 KB |
Output is correct |
12 |
Correct |
22 ms |
12504 KB |
Output is correct |
13 |
Correct |
23 ms |
12436 KB |
Output is correct |
14 |
Correct |
30 ms |
12576 KB |
Output is correct |
15 |
Correct |
23 ms |
13064 KB |
Output is correct |
16 |
Correct |
25 ms |
13076 KB |
Output is correct |
17 |
Correct |
22 ms |
12716 KB |
Output is correct |
18 |
Correct |
24 ms |
12764 KB |
Output is correct |
19 |
Correct |
24 ms |
12844 KB |
Output is correct |
20 |
Correct |
20 ms |
13388 KB |
Output is correct |
21 |
Correct |
19 ms |
13228 KB |
Output is correct |
22 |
Correct |
22 ms |
13340 KB |
Output is correct |
23 |
Correct |
28 ms |
13112 KB |
Output is correct |
24 |
Correct |
22 ms |
13120 KB |
Output is correct |
25 |
Correct |
23 ms |
13324 KB |
Output is correct |
26 |
Correct |
25 ms |
13228 KB |
Output is correct |
27 |
Correct |
27 ms |
13228 KB |
Output is correct |
28 |
Correct |
24 ms |
13100 KB |
Output is correct |
29 |
Correct |
23 ms |
13060 KB |
Output is correct |
30 |
Correct |
24 ms |
13128 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
38 ms |
14380 KB |
Output is correct |
2 |
Correct |
35 ms |
14436 KB |
Output is correct |
3 |
Correct |
35 ms |
14484 KB |
Output is correct |
4 |
Correct |
22 ms |
12520 KB |
Output is correct |
5 |
Correct |
23 ms |
14124 KB |
Output is correct |
6 |
Correct |
23 ms |
13472 KB |
Output is correct |
7 |
Correct |
23 ms |
12972 KB |
Output is correct |
8 |
Correct |
26 ms |
13356 KB |
Output is correct |
9 |
Correct |
28 ms |
13356 KB |
Output is correct |
10 |
Correct |
22 ms |
12680 KB |
Output is correct |
11 |
Correct |
20 ms |
12812 KB |
Output is correct |
12 |
Correct |
22 ms |
12624 KB |
Output is correct |
13 |
Correct |
24 ms |
12436 KB |
Output is correct |
14 |
Correct |
22 ms |
12836 KB |
Output is correct |
15 |
Correct |
22 ms |
13068 KB |
Output is correct |
16 |
Correct |
24 ms |
13068 KB |
Output is correct |
17 |
Correct |
24 ms |
12756 KB |
Output is correct |
18 |
Correct |
22 ms |
12884 KB |
Output is correct |
19 |
Correct |
23 ms |
12716 KB |
Output is correct |
20 |
Correct |
20 ms |
13356 KB |
Output is correct |
21 |
Correct |
20 ms |
13356 KB |
Output is correct |
22 |
Correct |
23 ms |
13100 KB |
Output is correct |
23 |
Correct |
24 ms |
13116 KB |
Output is correct |
24 |
Correct |
24 ms |
13116 KB |
Output is correct |
25 |
Correct |
25 ms |
13196 KB |
Output is correct |
26 |
Correct |
23 ms |
13100 KB |
Output is correct |
27 |
Correct |
23 ms |
13356 KB |
Output is correct |
28 |
Correct |
25 ms |
13396 KB |
Output is correct |
29 |
Correct |
26 ms |
13076 KB |
Output is correct |
30 |
Correct |
24 ms |
13112 KB |
Output is correct |
31 |
Correct |
6 ms |
10248 KB |
Output is correct |
32 |
Correct |
7 ms |
10492 KB |
Output is correct |
33 |
Correct |
7 ms |
10256 KB |
Output is correct |
34 |
Correct |
6 ms |
10492 KB |
Output is correct |
35 |
Correct |
7 ms |
10500 KB |
Output is correct |
36 |
Correct |
6 ms |
10504 KB |
Output is correct |
37 |
Correct |
6 ms |
10248 KB |
Output is correct |
38 |
Correct |
7 ms |
10384 KB |
Output is correct |
39 |
Correct |
10 ms |
10496 KB |
Output is correct |
40 |
Correct |
6 ms |
10492 KB |
Output is correct |
41 |
Correct |
6 ms |
10248 KB |
Output is correct |
42 |
Correct |
6 ms |
10248 KB |
Output is correct |