#include "Joi.h"
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int NM = 1e4;
namespace _Joi{
vector <int> g[NM+5], son[NM+5];
int parent[NM+5], dep[NM+5];
bool vis[NM+5], in_max_path[NM+5];
int MAX_DEP = 0, cnt = 0;
void dfs(int u, int p){
parent[u] = p;
if (p != -1) son[p].push_back(u);
dep[u] = (p == -1 ? 0 : dep[p]+1);
MAX_DEP = max(MAX_DEP, dep[u]);
vis[u] = 1;
for (int v : g[u]){
if (vis[v]) continue;
dfs(v, u);
}
}
void build(int u, ll X){
cnt++;
MessageBoard(u, (X>>(cnt-1))&1);
vis[u] = 1;
for (int v : son[u]){
if (!in_max_path[v]) continue;
build(v, X);
}
for (int v : son[u]){
if (in_max_path[v]) continue;
if (cnt < 60) build(v, X);
}
}
void solve(int N, int M, int A[], int B[], ll X, int T){
assert(T >= 1 && T <= 5);
for (int i = 0; i < M; i++){
g[A[i]].push_back(B[i]);
g[B[i]].push_back(A[i]);
}
dfs(0, -1);
if (MAX_DEP >= 60){
for (int i = 0; i < N; i++)
MessageBoard(i, (X>>(dep[i]%60))&1);
return;
}
bool found = 0;
for (int i = 0; i < N; i++)
if (dep[i] == MAX_DEP && !found){
found = 1;
for (int j = i; j != -1; j = parent[j]){
in_max_path[j] = 1;
}
}
for (int i = 0; i < N; i++) vis[i] = 0;
build(0, X);
for (int i = 0; i < N; i++)
if (!vis[i]) MessageBoard(i, 0);
}
}
void Joi(int N, int M, int A[], int B[], ll X, int T){
_Joi::solve(N, M, A, B, X, T);
}
#include "Joi.h"
#include "Ioi.h"
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int NM = 1e4;
namespace _Ioi{
vector <int> g[NM+5], son[NM+5];
int parent[NM+5], dep[NM+5];
bool vis[NM+5], in_max_path[NM+5];
int MAX_DEP = 0, cnt = 0;
int L[NM+5], f[NM+5];
ll X = 0;
void dfs(int u, int p){
parent[u] = p;
if (p != -1) son[p].push_back(u);
dep[u] = (p == -1 ? 0 : dep[p]+1);
MAX_DEP = max(MAX_DEP, dep[u]);
vis[u] = 1;
for (int v : g[u]){
if (vis[v]) continue;
dfs(v, u);
}
}
void build(int u){
cnt++;
L[u] = cnt-1;
for (int v : son[u]){
if (!in_max_path[v]) continue;
build(v);
}
for (int v : son[u]){
if (in_max_path[v]) continue;
if (cnt < 60) build(v);
}
}
void calc(int u){
f[u] = dep[u];
for (int v : son[u]){
calc(v);
f[u] = max(f[u], f[v]);
}
}
void get_ans(int u, int val){
if (val) X += (1LL<<L[u]);
for (int v : son[u]){
if (L[v] == -1) continue;
if (in_max_path[v]) continue;
get_ans(v, Move(v));
Move(u);
}
for (int v : son[u]){
if (L[v] == -1) continue;
if (!in_max_path[v]) continue;
get_ans(v, Move(v));
}
}
ll solve(int N, int M, int A[], int B[], int P, int V, int T){
assert(T >= 1 && T <= 5);
for (int i = 0; i < M; i++){
g[A[i]].push_back(B[i]);
g[B[i]].push_back(A[i]);
}
dfs(0, -1);
if (MAX_DEP >= 60){
if (dep[P] >= 60){
if (V) X += (1LL<<(dep[P]%60));
for (int i = 1; i < 60; i++){
P = parent[P];
V = Move(P);
if (V) X += (1LL<<(dep[P]%60));
}
}
else{
while (P > 0){
P = parent[P];
V = Move(P);
}
calc(0);
if (V) X++;
for (int i = 1; i < 60; i++){
for (int nxt : son[P]){
if (f[nxt] < 59) continue;
P = nxt;
V = Move(nxt);
if (V) X += (1LL<<i);
break;
}
}
}
return X;
}
bool found = 0;
for (int i = 0; i < N; i++)
if (dep[i] == MAX_DEP && !found){
found = 1;
for (int j = i; j != -1; j = parent[j]){
in_max_path[j] = 1;
}
}
for (int i = 0; i < N; i++) L[i] = -1;
build(0);
while (P > 0){
P = parent[P];
V = Move(P);
}
get_ans(0, V);
return X;
}
}
ll Ioi(int N, int M, int A[], int B[], int P, int V, int T){
return _Ioi::solve(N, M, A, B, P, V, T);
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
1808 KB |
Output is correct |
2 |
Correct |
2 ms |
1808 KB |
Output is correct |
3 |
Correct |
1 ms |
1816 KB |
Output is correct |
4 |
Correct |
0 ms |
1816 KB |
Output is correct |
5 |
Correct |
1 ms |
1820 KB |
Output is correct |
6 |
Correct |
1 ms |
1812 KB |
Output is correct |
7 |
Correct |
1 ms |
1828 KB |
Output is correct |
8 |
Correct |
1 ms |
1820 KB |
Output is correct |
9 |
Correct |
1 ms |
1828 KB |
Output is correct |
10 |
Correct |
1 ms |
2124 KB |
Output is correct |
11 |
Correct |
3 ms |
2144 KB |
Output is correct |
12 |
Correct |
1 ms |
1816 KB |
Output is correct |
13 |
Correct |
1 ms |
1820 KB |
Output is correct |
14 |
Correct |
1 ms |
1820 KB |
Output is correct |
15 |
Correct |
1 ms |
1828 KB |
Output is correct |
16 |
Correct |
1 ms |
1828 KB |
Output is correct |
17 |
Correct |
2 ms |
1820 KB |
Output is correct |
18 |
Correct |
2 ms |
1820 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
18 ms |
4948 KB |
Output is correct |
2 |
Correct |
17 ms |
4960 KB |
Output is correct |
3 |
Correct |
17 ms |
5056 KB |
Output is correct |
4 |
Correct |
11 ms |
3808 KB |
Output is correct |
5 |
Correct |
10 ms |
4292 KB |
Output is correct |
6 |
Correct |
11 ms |
3804 KB |
Output is correct |
7 |
Correct |
10 ms |
3800 KB |
Output is correct |
8 |
Correct |
11 ms |
4056 KB |
Output is correct |
9 |
Correct |
10 ms |
4056 KB |
Output is correct |
10 |
Correct |
9 ms |
3552 KB |
Output is correct |
11 |
Correct |
9 ms |
3552 KB |
Output is correct |
12 |
Correct |
10 ms |
3532 KB |
Output is correct |
13 |
Correct |
10 ms |
3532 KB |
Output is correct |
14 |
Correct |
11 ms |
3744 KB |
Output is correct |
15 |
Correct |
10 ms |
3800 KB |
Output is correct |
16 |
Correct |
10 ms |
3800 KB |
Output is correct |
17 |
Correct |
11 ms |
3812 KB |
Output is correct |
18 |
Correct |
10 ms |
3804 KB |
Output is correct |
19 |
Correct |
10 ms |
3600 KB |
Output is correct |
20 |
Correct |
9 ms |
4056 KB |
Output is correct |
21 |
Correct |
9 ms |
4056 KB |
Output is correct |
22 |
Correct |
11 ms |
3804 KB |
Output is correct |
23 |
Correct |
11 ms |
4152 KB |
Output is correct |
24 |
Correct |
10 ms |
3908 KB |
Output is correct |
25 |
Correct |
10 ms |
3896 KB |
Output is correct |
26 |
Correct |
11 ms |
4160 KB |
Output is correct |
27 |
Correct |
10 ms |
4160 KB |
Output is correct |
28 |
Correct |
11 ms |
4152 KB |
Output is correct |
29 |
Correct |
11 ms |
3872 KB |
Output is correct |
30 |
Correct |
10 ms |
3884 KB |
Output is correct |
31 |
Correct |
1 ms |
1812 KB |
Output is correct |
32 |
Correct |
1 ms |
1820 KB |
Output is correct |
33 |
Correct |
1 ms |
1824 KB |
Output is correct |
34 |
Correct |
2 ms |
1824 KB |
Output is correct |
35 |
Correct |
2 ms |
1824 KB |
Output is correct |
36 |
Correct |
1 ms |
1828 KB |
Output is correct |
37 |
Correct |
1 ms |
1812 KB |
Output is correct |
38 |
Correct |
1 ms |
1812 KB |
Output is correct |
39 |
Correct |
1 ms |
1820 KB |
Output is correct |
40 |
Correct |
0 ms |
1812 KB |
Output is correct |
41 |
Correct |
1 ms |
1824 KB |
Output is correct |
42 |
Correct |
1 ms |
1816 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2072 KB |
Output is correct |
2 |
Correct |
1 ms |
1820 KB |
Output is correct |
3 |
Correct |
1 ms |
1812 KB |
Output is correct |
4 |
Correct |
2 ms |
2368 KB |
Output is correct |
5 |
Correct |
3 ms |
2376 KB |
Output is correct |
6 |
Correct |
2 ms |
2364 KB |
Output is correct |
7 |
Correct |
2 ms |
2368 KB |
Output is correct |
8 |
Correct |
3 ms |
2368 KB |
Output is correct |
9 |
Correct |
9 ms |
4920 KB |
Output is correct |
10 |
Correct |
9 ms |
4928 KB |
Output is correct |
11 |
Correct |
9 ms |
4920 KB |
Output is correct |
12 |
Correct |
1 ms |
1812 KB |
Output is correct |
13 |
Correct |
1 ms |
1812 KB |
Output is correct |
14 |
Correct |
1 ms |
1820 KB |
Output is correct |
15 |
Correct |
1 ms |
1824 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
18 ms |
5028 KB |
Output is correct |
2 |
Correct |
17 ms |
4972 KB |
Output is correct |
3 |
Correct |
17 ms |
4952 KB |
Output is correct |
4 |
Correct |
11 ms |
3800 KB |
Output is correct |
5 |
Correct |
11 ms |
4564 KB |
Output is correct |
6 |
Correct |
11 ms |
4060 KB |
Output is correct |
7 |
Correct |
10 ms |
4416 KB |
Output is correct |
8 |
Correct |
10 ms |
3904 KB |
Output is correct |
9 |
Correct |
10 ms |
4368 KB |
Output is correct |
10 |
Correct |
9 ms |
3908 KB |
Output is correct |
11 |
Correct |
11 ms |
3904 KB |
Output is correct |
12 |
Correct |
9 ms |
3876 KB |
Output is correct |
13 |
Correct |
11 ms |
3820 KB |
Output is correct |
14 |
Correct |
9 ms |
4400 KB |
Output is correct |
15 |
Correct |
10 ms |
3900 KB |
Output is correct |
16 |
Correct |
10 ms |
3904 KB |
Output is correct |
17 |
Correct |
11 ms |
3900 KB |
Output is correct |
18 |
Correct |
10 ms |
3904 KB |
Output is correct |
19 |
Correct |
12 ms |
3896 KB |
Output is correct |
20 |
Correct |
9 ms |
4416 KB |
Output is correct |
21 |
Correct |
11 ms |
4400 KB |
Output is correct |
22 |
Correct |
10 ms |
4152 KB |
Output is correct |
23 |
Correct |
12 ms |
3908 KB |
Output is correct |
24 |
Correct |
11 ms |
3908 KB |
Output is correct |
25 |
Correct |
11 ms |
4148 KB |
Output is correct |
26 |
Correct |
10 ms |
4152 KB |
Output is correct |
27 |
Correct |
11 ms |
4912 KB |
Output is correct |
28 |
Correct |
10 ms |
3900 KB |
Output is correct |
29 |
Correct |
9 ms |
3884 KB |
Output is correct |
30 |
Correct |
10 ms |
3884 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
17 ms |
5084 KB |
Output is correct |
2 |
Correct |
18 ms |
5044 KB |
Output is correct |
3 |
Correct |
17 ms |
4960 KB |
Output is correct |
4 |
Correct |
11 ms |
3800 KB |
Output is correct |
5 |
Correct |
12 ms |
4568 KB |
Output is correct |
6 |
Correct |
11 ms |
3820 KB |
Output is correct |
7 |
Correct |
10 ms |
3796 KB |
Output is correct |
8 |
Correct |
11 ms |
4064 KB |
Output is correct |
9 |
Correct |
11 ms |
3808 KB |
Output is correct |
10 |
Correct |
9 ms |
3548 KB |
Output is correct |
11 |
Correct |
9 ms |
3544 KB |
Output is correct |
12 |
Correct |
9 ms |
3536 KB |
Output is correct |
13 |
Correct |
9 ms |
3536 KB |
Output is correct |
14 |
Correct |
9 ms |
3536 KB |
Output is correct |
15 |
Correct |
10 ms |
3804 KB |
Output is correct |
16 |
Correct |
11 ms |
3808 KB |
Output is correct |
17 |
Correct |
11 ms |
3800 KB |
Output is correct |
18 |
Correct |
11 ms |
3808 KB |
Output is correct |
19 |
Correct |
10 ms |
3808 KB |
Output is correct |
20 |
Correct |
9 ms |
4060 KB |
Output is correct |
21 |
Correct |
8 ms |
4056 KB |
Output is correct |
22 |
Correct |
11 ms |
3808 KB |
Output is correct |
23 |
Correct |
11 ms |
3792 KB |
Output is correct |
24 |
Correct |
10 ms |
3800 KB |
Output is correct |
25 |
Correct |
10 ms |
3808 KB |
Output is correct |
26 |
Correct |
10 ms |
3808 KB |
Output is correct |
27 |
Correct |
10 ms |
4056 KB |
Output is correct |
28 |
Correct |
11 ms |
4064 KB |
Output is correct |
29 |
Correct |
9 ms |
3784 KB |
Output is correct |
30 |
Correct |
10 ms |
3996 KB |
Output is correct |
31 |
Correct |
2 ms |
1816 KB |
Output is correct |
32 |
Correct |
1 ms |
1812 KB |
Output is correct |
33 |
Correct |
1 ms |
1816 KB |
Output is correct |
34 |
Correct |
1 ms |
1820 KB |
Output is correct |
35 |
Correct |
2 ms |
1808 KB |
Output is correct |
36 |
Correct |
1 ms |
1824 KB |
Output is correct |
37 |
Correct |
0 ms |
1824 KB |
Output is correct |
38 |
Correct |
1 ms |
1808 KB |
Output is correct |
39 |
Correct |
1 ms |
1824 KB |
Output is correct |
40 |
Correct |
2 ms |
1820 KB |
Output is correct |
41 |
Correct |
1 ms |
1824 KB |
Output is correct |
42 |
Correct |
1 ms |
1812 KB |
Output is correct |