#include <bits/stdc++.h>
#include "Joi.h"
using namespace std;
const int Z = 1e4;
int dfsTimer, e[Z];
bool vis[Z];
vector<int> g[Z], h[Z];
long long x;
int init(int u, int d = 0) {
vis[u] = 1;
e[u] = d;
for(const int &v : g[u]) if(!vis[v]) {
e[u] = max(e[u], init(v, d + 1));
h[u].push_back(v);
}
sort(begin(h[u]), end(h[u]), [&](const int &i, const int &j) {
return e[i] > e[j];
});
return e[u];
}
void dfs(int u) {
MessageBoard(u, bool(x & (1LL<<(++dfsTimer % 60))));
for(const int &v : h[u]) dfs(v);
}
void Joi(int N, int M, int A[], int B[], long long X, int _T) {
x = X;
for(int i = 0; i < M; ++i) {
g[A[i]].push_back(B[i]);
g[B[i]].push_back(A[i]);
}
init(0);
dfs(0);
}
#include <bits/stdc++.h>
#include "Ioi.h"
using namespace std;
const int Z = 1e4;
int L[Z], R[Z], dfsTimer, e[Z], p[Z];
vector<int> g[Z], h[Z];
int init(int u, int d = 0) {
L[u] = ++dfsTimer;
e[u] = d;
for(const int &v : g[u]) if(!L[v]) {
p[v] = u;
e[u] = max(e[u], init(v, d + 1));
h[u].push_back(v);
}
sort(begin(h[u]), end(h[u]), [&](const int &i, const int &j) {
return e[i] > e[j];
});
R[u] = 1+dfsTimer;
return e[u];
}
int r;
vector<pair<int, int>> path;
#define valid(X) (L[r] <= X && X < L[r] + 60)
void dfs(int u) {
L[u] = ++dfsTimer;
for(const int &v : h[u]) {
if(valid(L[u]) && valid(dfsTimer+1))
path.emplace_back(u, v);
dfs(v);
if(valid(L[u]) && valid(L[v]))
path.emplace_back(v, u);
}
}
long long Ioi(int N, int M, int A[], int B[], int P, int V, int T) {
for(int i = 0; i < M; ++i) {
g[A[i]].push_back(B[i]);
g[B[i]].push_back(A[i]);
}
init(0);
r = P;
while(R[r] - L[r] < 60) V = Move(r = p[r]);
dfs(dfsTimer = 0);
long long x {};
set<int> done;
done.insert(L[r] % 60);
if(V) x |= 1LL << (L[r] % 60);
while(size(done) < 60) {
auto [v, pos] = path.back();
path.pop_back();
done.insert(pos = L[v] % 60);
if(Move(r = v))
x |= 1LL << pos;
}
return x;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
1520 KB |
Output is correct |
2 |
Correct |
2 ms |
1512 KB |
Output is correct |
3 |
Correct |
2 ms |
1516 KB |
Output is correct |
4 |
Correct |
2 ms |
1512 KB |
Output is correct |
5 |
Correct |
2 ms |
1512 KB |
Output is correct |
6 |
Correct |
2 ms |
1512 KB |
Output is correct |
7 |
Correct |
2 ms |
1524 KB |
Output is correct |
8 |
Correct |
2 ms |
1516 KB |
Output is correct |
9 |
Correct |
2 ms |
1520 KB |
Output is correct |
10 |
Correct |
2 ms |
1520 KB |
Output is correct |
11 |
Correct |
4 ms |
1960 KB |
Output is correct |
12 |
Correct |
2 ms |
1520 KB |
Output is correct |
13 |
Correct |
2 ms |
1520 KB |
Output is correct |
14 |
Correct |
2 ms |
1524 KB |
Output is correct |
15 |
Correct |
2 ms |
1524 KB |
Output is correct |
16 |
Correct |
2 ms |
1516 KB |
Output is correct |
17 |
Correct |
2 ms |
1512 KB |
Output is correct |
18 |
Correct |
2 ms |
1524 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
24 ms |
5292 KB |
Output is correct |
2 |
Correct |
22 ms |
5320 KB |
Output is correct |
3 |
Correct |
24 ms |
5300 KB |
Output is correct |
4 |
Correct |
16 ms |
3576 KB |
Output is correct |
5 |
Correct |
14 ms |
4516 KB |
Output is correct |
6 |
Correct |
13 ms |
4036 KB |
Output is correct |
7 |
Correct |
13 ms |
4144 KB |
Output is correct |
8 |
Correct |
13 ms |
4272 KB |
Output is correct |
9 |
Correct |
13 ms |
4236 KB |
Output is correct |
10 |
Correct |
12 ms |
3336 KB |
Output is correct |
11 |
Correct |
12 ms |
3380 KB |
Output is correct |
12 |
Correct |
11 ms |
3368 KB |
Output is correct |
13 |
Correct |
12 ms |
3264 KB |
Output is correct |
14 |
Correct |
13 ms |
3376 KB |
Output is correct |
15 |
Correct |
13 ms |
3656 KB |
Output is correct |
16 |
Correct |
13 ms |
3640 KB |
Output is correct |
17 |
Correct |
13 ms |
3652 KB |
Output is correct |
18 |
Correct |
13 ms |
3504 KB |
Output is correct |
19 |
Correct |
14 ms |
3644 KB |
Output is correct |
20 |
Correct |
11 ms |
4280 KB |
Output is correct |
21 |
Correct |
11 ms |
4276 KB |
Output is correct |
22 |
Correct |
14 ms |
3880 KB |
Output is correct |
23 |
Correct |
15 ms |
4100 KB |
Output is correct |
24 |
Correct |
14 ms |
3884 KB |
Output is correct |
25 |
Correct |
13 ms |
4008 KB |
Output is correct |
26 |
Correct |
14 ms |
4144 KB |
Output is correct |
27 |
Correct |
18 ms |
4080 KB |
Output is correct |
28 |
Correct |
14 ms |
4272 KB |
Output is correct |
29 |
Correct |
12 ms |
3888 KB |
Output is correct |
30 |
Correct |
14 ms |
4004 KB |
Output is correct |
31 |
Correct |
2 ms |
1512 KB |
Output is correct |
32 |
Correct |
2 ms |
1512 KB |
Output is correct |
33 |
Correct |
2 ms |
1624 KB |
Output is correct |
34 |
Correct |
2 ms |
1512 KB |
Output is correct |
35 |
Correct |
2 ms |
1512 KB |
Output is correct |
36 |
Correct |
2 ms |
1512 KB |
Output is correct |
37 |
Correct |
1 ms |
1508 KB |
Output is correct |
38 |
Correct |
2 ms |
1520 KB |
Output is correct |
39 |
Correct |
2 ms |
1516 KB |
Output is correct |
40 |
Correct |
2 ms |
1520 KB |
Output is correct |
41 |
Correct |
2 ms |
1516 KB |
Output is correct |
42 |
Correct |
2 ms |
1520 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
1512 KB |
Output is correct |
2 |
Correct |
2 ms |
1520 KB |
Output is correct |
3 |
Correct |
2 ms |
1520 KB |
Output is correct |
4 |
Correct |
2 ms |
2180 KB |
Output is correct |
5 |
Correct |
3 ms |
2132 KB |
Output is correct |
6 |
Correct |
3 ms |
2192 KB |
Output is correct |
7 |
Correct |
3 ms |
2192 KB |
Output is correct |
8 |
Correct |
3 ms |
2180 KB |
Output is correct |
9 |
Correct |
12 ms |
5420 KB |
Output is correct |
10 |
Correct |
12 ms |
5440 KB |
Output is correct |
11 |
Correct |
11 ms |
5484 KB |
Output is correct |
12 |
Correct |
2 ms |
1520 KB |
Output is correct |
13 |
Correct |
2 ms |
1512 KB |
Output is correct |
14 |
Correct |
2 ms |
1512 KB |
Output is correct |
15 |
Correct |
2 ms |
1512 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
23 ms |
5308 KB |
Output is correct |
2 |
Correct |
23 ms |
5336 KB |
Output is correct |
3 |
Correct |
23 ms |
5308 KB |
Output is correct |
4 |
Correct |
14 ms |
3520 KB |
Output is correct |
5 |
Correct |
16 ms |
5052 KB |
Output is correct |
6 |
Correct |
13 ms |
4280 KB |
Output is correct |
7 |
Correct |
13 ms |
4252 KB |
Output is correct |
8 |
Correct |
14 ms |
3792 KB |
Output is correct |
9 |
Correct |
18 ms |
4020 KB |
Output is correct |
10 |
Correct |
12 ms |
3344 KB |
Output is correct |
11 |
Correct |
14 ms |
3492 KB |
Output is correct |
12 |
Correct |
12 ms |
3376 KB |
Output is correct |
13 |
Correct |
14 ms |
3372 KB |
Output is correct |
14 |
Correct |
14 ms |
3356 KB |
Output is correct |
15 |
Correct |
15 ms |
3620 KB |
Output is correct |
16 |
Correct |
14 ms |
3672 KB |
Output is correct |
17 |
Correct |
14 ms |
3640 KB |
Output is correct |
18 |
Correct |
14 ms |
3500 KB |
Output is correct |
19 |
Correct |
13 ms |
3640 KB |
Output is correct |
20 |
Correct |
12 ms |
4260 KB |
Output is correct |
21 |
Correct |
13 ms |
4252 KB |
Output is correct |
22 |
Correct |
13 ms |
4032 KB |
Output is correct |
23 |
Correct |
14 ms |
3996 KB |
Output is correct |
24 |
Correct |
15 ms |
4056 KB |
Output is correct |
25 |
Correct |
19 ms |
4196 KB |
Output is correct |
26 |
Correct |
14 ms |
4036 KB |
Output is correct |
27 |
Correct |
14 ms |
4204 KB |
Output is correct |
28 |
Correct |
13 ms |
3904 KB |
Output is correct |
29 |
Correct |
12 ms |
3884 KB |
Output is correct |
30 |
Correct |
13 ms |
4024 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
25 ms |
5328 KB |
Output is correct |
2 |
Correct |
22 ms |
5324 KB |
Output is correct |
3 |
Correct |
24 ms |
5268 KB |
Output is correct |
4 |
Correct |
14 ms |
3480 KB |
Output is correct |
5 |
Correct |
15 ms |
5028 KB |
Output is correct |
6 |
Correct |
15 ms |
4020 KB |
Output is correct |
7 |
Correct |
14 ms |
3992 KB |
Output is correct |
8 |
Correct |
13 ms |
4228 KB |
Output is correct |
9 |
Correct |
13 ms |
4156 KB |
Output is correct |
10 |
Correct |
12 ms |
3380 KB |
Output is correct |
11 |
Correct |
12 ms |
3420 KB |
Output is correct |
12 |
Correct |
13 ms |
3352 KB |
Output is correct |
13 |
Correct |
12 ms |
3380 KB |
Output is correct |
14 |
Correct |
13 ms |
3372 KB |
Output is correct |
15 |
Correct |
13 ms |
3648 KB |
Output is correct |
16 |
Correct |
16 ms |
3684 KB |
Output is correct |
17 |
Correct |
14 ms |
3648 KB |
Output is correct |
18 |
Correct |
14 ms |
3648 KB |
Output is correct |
19 |
Correct |
15 ms |
3572 KB |
Output is correct |
20 |
Correct |
11 ms |
4288 KB |
Output is correct |
21 |
Correct |
11 ms |
4240 KB |
Output is correct |
22 |
Correct |
14 ms |
4060 KB |
Output is correct |
23 |
Correct |
15 ms |
4024 KB |
Output is correct |
24 |
Correct |
14 ms |
4012 KB |
Output is correct |
25 |
Correct |
13 ms |
3968 KB |
Output is correct |
26 |
Correct |
15 ms |
3900 KB |
Output is correct |
27 |
Correct |
18 ms |
4352 KB |
Output is correct |
28 |
Correct |
15 ms |
4288 KB |
Output is correct |
29 |
Correct |
13 ms |
4000 KB |
Output is correct |
30 |
Correct |
13 ms |
4024 KB |
Output is correct |
31 |
Correct |
2 ms |
1512 KB |
Output is correct |
32 |
Correct |
2 ms |
1520 KB |
Output is correct |
33 |
Correct |
2 ms |
1516 KB |
Output is correct |
34 |
Correct |
2 ms |
1520 KB |
Output is correct |
35 |
Correct |
2 ms |
1520 KB |
Output is correct |
36 |
Correct |
2 ms |
1512 KB |
Output is correct |
37 |
Correct |
2 ms |
1520 KB |
Output is correct |
38 |
Correct |
2 ms |
1520 KB |
Output is correct |
39 |
Correct |
2 ms |
1512 KB |
Output is correct |
40 |
Correct |
2 ms |
1512 KB |
Output is correct |
41 |
Correct |
2 ms |
1512 KB |
Output is correct |
42 |
Correct |
2 ms |
1516 KB |
Output is correct |