#include<bits/stdc++.h>
#include"Joi.h"
using namespace std;
#define color MessageBoard
#define app push_back
const int N = 20001;
vector <int> g[N];
int tin[N], ptr = 0;
bool used[N];
void dfs(int u, long long x) {
used[u] = 1;
tin[u] = ptr++;
int b = tin[u] % 60;
color(u, (x >> b) & 1);
for (int v : g[u]) {
if (!used[v]) {
dfs(v, x);
}
}
}
void Joi(int n, int m, int a[], int b[], long long x, int t) {
for (int i = 0; i < m; ++i) {
g[a[i]].app(b[i]);
g[b[i]].app(a[i]);
}
dfs(0, x);
}
#include<bits/stdc++.h>
#include"Ioi.h"
#define move Move
#define app push_back
using namespace std;
const int N = 20001;
vector <int> g[N];
int tin[N], cnt[N], par[N], ptr = 0;
bool used[N];
vector <int> tree[N];
void dfs(int u) {
used[u] = 1; cnt[u] = 1; tin[u] = ptr++;
for (int v : g[u]) {
if (!used[v]) {
dfs(v);
par[v] = u; tree[u].app(v); cnt[u] += cnt[v];
}
}
}
int vis = 0;
bool want[N], mem[N];
int vert[60];
int ans[N];
void dfs1(int u, int p) {
if (vis == 60) return;
++vis;
int b = tin[u] % 60;
want[u] = vert[b] == -1;
bool want0 = want[u];
for (int v : tree[u]) {
dfs1(v, u);
want[u] |= want[v];
mem[u] |= mem[v];
}
mem[u] |= !want0 && want[u];
}
bool comp(int u, int v) {
return mem[u] < mem[v];
}
void dfs2(int u, int p) {
if (tree[u].empty()) return;
sort(tree[u].begin(), tree[u].end(), comp);
for (int v : tree[u]) {
if (want[v]) {
vert[tin[v] % 60] = v;
ans[v] = move(v);
dfs2(v, u);
if (!mem[v]) {
move(u);
}
}
}
}
long long Ioi(int n, int m, int a[], int b[], int u, int v, int t) {
for (int i = 0; i < 60; ++i) vert[i] = -1;
for (int i = 0; i < m; ++i) {
g[a[i]].app(b[i]);
g[b[i]].app(a[i]);
}
dfs(0);
ans[u] = v;
vert[tin[u] % 60] = u;
while (cnt[u] < 60) {
u = par[u];
ans[u] = move(u);
vert[tin[u] % 60] = u;
}
dfs1(u, par[u]);
if (want[u]) dfs2(u, par[u]);
long long x = 0;
for (int i = 0; i < 60; ++i) {
x += (1ll << i) * ans[vert[i]];
}
return x;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
2188 KB |
Output is correct |
2 |
Correct |
5 ms |
2168 KB |
Output is correct |
3 |
Correct |
6 ms |
2172 KB |
Output is correct |
4 |
Correct |
5 ms |
2300 KB |
Output is correct |
5 |
Correct |
5 ms |
2164 KB |
Output is correct |
6 |
Correct |
5 ms |
2164 KB |
Output is correct |
7 |
Correct |
6 ms |
2172 KB |
Output is correct |
8 |
Correct |
6 ms |
2172 KB |
Output is correct |
9 |
Correct |
6 ms |
2300 KB |
Output is correct |
10 |
Correct |
6 ms |
2376 KB |
Output is correct |
11 |
Correct |
9 ms |
2752 KB |
Output is correct |
12 |
Correct |
5 ms |
2164 KB |
Output is correct |
13 |
Correct |
8 ms |
2172 KB |
Output is correct |
14 |
Correct |
6 ms |
2308 KB |
Output is correct |
15 |
Correct |
6 ms |
2176 KB |
Output is correct |
16 |
Correct |
7 ms |
2408 KB |
Output is correct |
17 |
Correct |
6 ms |
2312 KB |
Output is correct |
18 |
Correct |
6 ms |
2408 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
35 ms |
5908 KB |
Output is correct |
2 |
Correct |
34 ms |
5792 KB |
Output is correct |
3 |
Correct |
34 ms |
5748 KB |
Output is correct |
4 |
Correct |
20 ms |
4116 KB |
Output is correct |
5 |
Correct |
23 ms |
4748 KB |
Output is correct |
6 |
Correct |
22 ms |
4628 KB |
Output is correct |
7 |
Correct |
22 ms |
4680 KB |
Output is correct |
8 |
Correct |
22 ms |
4748 KB |
Output is correct |
9 |
Correct |
22 ms |
4820 KB |
Output is correct |
10 |
Correct |
20 ms |
4280 KB |
Output is correct |
11 |
Correct |
20 ms |
4112 KB |
Output is correct |
12 |
Correct |
20 ms |
4088 KB |
Output is correct |
13 |
Correct |
20 ms |
4088 KB |
Output is correct |
14 |
Correct |
20 ms |
4096 KB |
Output is correct |
15 |
Correct |
22 ms |
4292 KB |
Output is correct |
16 |
Correct |
22 ms |
4292 KB |
Output is correct |
17 |
Correct |
22 ms |
4372 KB |
Output is correct |
18 |
Correct |
24 ms |
4108 KB |
Output is correct |
19 |
Incorrect |
22 ms |
4240 KB |
Wrong Answer [7] |
20 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
2516 KB |
Output is correct |
2 |
Correct |
6 ms |
2164 KB |
Output is correct |
3 |
Correct |
5 ms |
2300 KB |
Output is correct |
4 |
Correct |
8 ms |
2732 KB |
Output is correct |
5 |
Correct |
7 ms |
2720 KB |
Output is correct |
6 |
Correct |
7 ms |
2720 KB |
Output is correct |
7 |
Correct |
7 ms |
2788 KB |
Output is correct |
8 |
Correct |
7 ms |
2720 KB |
Output is correct |
9 |
Correct |
18 ms |
5388 KB |
Output is correct |
10 |
Correct |
18 ms |
5260 KB |
Output is correct |
11 |
Correct |
17 ms |
5260 KB |
Output is correct |
12 |
Correct |
5 ms |
2300 KB |
Output is correct |
13 |
Correct |
5 ms |
2420 KB |
Output is correct |
14 |
Correct |
5 ms |
2164 KB |
Output is correct |
15 |
Correct |
5 ms |
2164 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
33 ms |
5812 KB |
Output is correct |
2 |
Correct |
33 ms |
5692 KB |
Output is correct |
3 |
Correct |
33 ms |
5684 KB |
Output is correct |
4 |
Correct |
20 ms |
4236 KB |
Output is correct |
5 |
Correct |
22 ms |
5004 KB |
Output is correct |
6 |
Correct |
22 ms |
4748 KB |
Output is correct |
7 |
Correct |
22 ms |
4624 KB |
Output is correct |
8 |
Correct |
22 ms |
4580 KB |
Output is correct |
9 |
Correct |
22 ms |
4364 KB |
Output is correct |
10 |
Correct |
20 ms |
4256 KB |
Output is correct |
11 |
Correct |
20 ms |
4240 KB |
Output is correct |
12 |
Correct |
20 ms |
3968 KB |
Output is correct |
13 |
Correct |
19 ms |
4212 KB |
Output is correct |
14 |
Correct |
20 ms |
4104 KB |
Output is correct |
15 |
Correct |
20 ms |
4448 KB |
Output is correct |
16 |
Correct |
22 ms |
4372 KB |
Output is correct |
17 |
Correct |
20 ms |
4244 KB |
Output is correct |
18 |
Correct |
22 ms |
4288 KB |
Output is correct |
19 |
Correct |
20 ms |
4236 KB |
Output is correct |
20 |
Correct |
18 ms |
4756 KB |
Output is correct |
21 |
Correct |
17 ms |
4668 KB |
Output is correct |
22 |
Correct |
22 ms |
4632 KB |
Output is correct |
23 |
Correct |
22 ms |
4620 KB |
Output is correct |
24 |
Correct |
22 ms |
4540 KB |
Output is correct |
25 |
Correct |
22 ms |
4688 KB |
Output is correct |
26 |
Correct |
22 ms |
4632 KB |
Output is correct |
27 |
Correct |
22 ms |
4756 KB |
Output is correct |
28 |
Correct |
22 ms |
4628 KB |
Output is correct |
29 |
Correct |
20 ms |
4312 KB |
Output is correct |
30 |
Correct |
22 ms |
4500 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
34 ms |
5776 KB |
Output is correct |
2 |
Correct |
34 ms |
5692 KB |
Output is correct |
3 |
Correct |
33 ms |
5820 KB |
Output is correct |
4 |
Correct |
20 ms |
4244 KB |
Output is correct |
5 |
Correct |
22 ms |
5296 KB |
Output is correct |
6 |
Correct |
22 ms |
4640 KB |
Output is correct |
7 |
Correct |
22 ms |
4516 KB |
Output is correct |
8 |
Correct |
22 ms |
4632 KB |
Output is correct |
9 |
Correct |
23 ms |
4704 KB |
Output is correct |
10 |
Correct |
20 ms |
4504 KB |
Output is correct |
11 |
Correct |
20 ms |
4376 KB |
Output is correct |
12 |
Correct |
20 ms |
4232 KB |
Output is correct |
13 |
Correct |
20 ms |
4100 KB |
Output is correct |
14 |
Correct |
20 ms |
4108 KB |
Output is correct |
15 |
Correct |
20 ms |
4376 KB |
Output is correct |
16 |
Correct |
22 ms |
4384 KB |
Output is correct |
17 |
Correct |
22 ms |
4252 KB |
Output is correct |
18 |
Correct |
22 ms |
4284 KB |
Output is correct |
19 |
Correct |
22 ms |
4284 KB |
Output is correct |
20 |
Correct |
19 ms |
4768 KB |
Output is correct |
21 |
Correct |
18 ms |
4644 KB |
Output is correct |
22 |
Correct |
23 ms |
4632 KB |
Output is correct |
23 |
Correct |
24 ms |
4632 KB |
Output is correct |
24 |
Correct |
24 ms |
4736 KB |
Output is correct |
25 |
Correct |
23 ms |
4640 KB |
Output is correct |
26 |
Correct |
22 ms |
4512 KB |
Output is correct |
27 |
Correct |
22 ms |
4768 KB |
Output is correct |
28 |
Correct |
22 ms |
4760 KB |
Output is correct |
29 |
Correct |
20 ms |
4616 KB |
Output is correct |
30 |
Correct |
22 ms |
4720 KB |
Output is correct |
31 |
Incorrect |
6 ms |
2544 KB |
Wrong Answer [7] |
32 |
Halted |
0 ms |
0 KB |
- |