#include "Anyalib.h"
#include <algorithm>
#include <vector>
using namespace std;
const static int t = 11;
typedef pair<int, int> pii;
const static int MAXN = 500;
static int n;
static vector<pii> edge[MAXN];
static int s[MAXN], e[MAXN];
static pii close[MAXN];
static void dfs1(int x, int p, pii cl) {
if (cl.first > t) {
cl = pii(0, x);
}
close[x] = cl;
++cl.first;
for (pii i : edge[x]) {
if (i.second == p) continue;
dfs1(i.second, x, cl);
pii tp = close[i.second];
tp.first += 2;
cl = min(cl, tp);
}
}
static int dist[MAXN];
static int par[MAXN];
static void dfs2(int x, int p, int d, int C[]) {
dist[x] = d;
for (pii i : edge[x]) {
if (i.second == p) continue;
par[i.second] = C[i.first];
dfs2(i.second, x, d + C[i.first], C);
}
}
void InitAnya(int N , int A[] , int B[]) {
n = N;
for (int i = 0; i < n - 1; ++i) {
edge[A[i]].emplace_back(i, B[i]);
edge[B[i]].emplace_back(i, A[i]);
}
dfs1(0, -1, pii(20, -1));
int p = 0;
for (int i = 0; i < n; ++i) {
s[i] = p;
p = p + (close[i].first ? 1 : 10);
e[i] = p - 1;
}
}
void Anya(int C[]) {
dfs2(0, -1, 0, C);
for (int i = 0; i < n; ++i) {
Save(s[i], par[i]);
for (int j = s[i] + 1; j <= e[i]; ++j) {
Save(j, dist[i] & 1);
dist[i] >>= 1;
}
}
}
#include "Borislib.h"
#include <algorithm>
#include <vector>
using namespace std;
const static int t = 11;
typedef pair<int, int> pii;
const static int MAXN = 500;
static int n;
static vector<pii> edge[MAXN];
static int s[MAXN], e[MAXN];
static pii close[MAXN];
static int par[MAXN];
static int dep[MAXN];
static void dfs1(int x, int p, pii cl) {
par[x] = p;
if (cl.first > t) {
cl = pii(0, x);
}
close[x] = cl;
++cl.first;
for (pii i : edge[x]) {
if (i.second == p) continue;
dep[i.second] = dep[x] + 1;
dfs1(i.second, x, cl);
pii tp = close[i.second];
tp.first += 2;
cl = min(cl, tp);
}
}
void InitBoris(int N , int A[] , int B[]) {
n = N;
for (int i = 0; i < n - 1; ++i) {
edge[A[i]].emplace_back(i, B[i]);
edge[B[i]].emplace_back(i, A[i]);
}
dfs1(0, -1, pii(20, -1));
int p = 0;
for (int i = 0; i < n; ++i) {
s[i] = p;
p = p + (close[i].first ? 1 : 10);
e[i] = p - 1;
}
}
int Boris(int x) {
int y = close[x].second;
int ret = 0;
for (int i = e[y]; i > s[y]; --i) {
ret <<= 1;
ret += Ask(i);
}
while (dep[x] < dep[y]) {
ret -= Ask(s[y]);
y = par[y];
}
while (dep[x] > dep[y]) {
ret += Ask(s[x]);
x = par[x];
}
while (x != y) {
ret += Ask(s[x]) - Ask(s[y]);
x = par[x];
y = par[y];
}
return ret;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
832 KB |
Output is correct |
2 |
Correct |
7 ms |
1384 KB |
Output is correct |
3 |
Correct |
8 ms |
1508 KB |
Output is correct |
4 |
Correct |
7 ms |
1664 KB |
Output is correct |
5 |
Correct |
9 ms |
1696 KB |
Output is correct |
6 |
Correct |
10 ms |
1716 KB |
Output is correct |
7 |
Correct |
9 ms |
1740 KB |
Output is correct |
8 |
Correct |
10 ms |
1752 KB |
Output is correct |
9 |
Correct |
9 ms |
1984 KB |
Output is correct |
10 |
Correct |
11 ms |
1984 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
11 ms |
1984 KB |
Output is correct |
2 |
Correct |
14 ms |
2016 KB |
Output is correct |
3 |
Correct |
13 ms |
2016 KB |
Output is correct |
4 |
Correct |
11 ms |
2016 KB |
Output is correct |
5 |
Correct |
12 ms |
2016 KB |
Output is correct |
6 |
Correct |
11 ms |
2016 KB |
Output is correct |
7 |
Correct |
12 ms |
2016 KB |
Output is correct |
8 |
Correct |
10 ms |
2016 KB |
Output is correct |
9 |
Correct |
11 ms |
2016 KB |
Output is correct |
10 |
Correct |
10 ms |
2016 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
21 ms |
2016 KB |
Output is correct |
2 |
Correct |
25 ms |
2024 KB |
Output is correct |
3 |
Correct |
19 ms |
2024 KB |
Output is correct |
4 |
Correct |
22 ms |
2024 KB |
Output is correct |
5 |
Correct |
24 ms |
2024 KB |
Output is correct |
6 |
Correct |
22 ms |
2024 KB |
Output is correct |
7 |
Correct |
19 ms |
2024 KB |
Output is correct |
8 |
Correct |
21 ms |
2024 KB |
Output is correct |
9 |
Correct |
22 ms |
2024 KB |
Output is correct |
10 |
Correct |
19 ms |
2024 KB |
Output is correct |
11 |
Correct |
20 ms |
2024 KB |
Output is correct |
12 |
Correct |
19 ms |
2024 KB |
Output is correct |
13 |
Correct |
20 ms |
2024 KB |
Output is correct |
14 |
Correct |
20 ms |
2136 KB |
Output is correct |
15 |
Correct |
19 ms |
2136 KB |
Output is correct |
16 |
Correct |
20 ms |
2136 KB |
Output is correct |
17 |
Correct |
20 ms |
2136 KB |
Output is correct |
18 |
Correct |
20 ms |
2136 KB |
Output is correct |
19 |
Correct |
19 ms |
2136 KB |
Output is correct |
20 |
Correct |
23 ms |
2136 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
19 ms |
2136 KB |
Output is correct |
2 |
Correct |
17 ms |
2136 KB |
Output is correct |
3 |
Correct |
17 ms |
2136 KB |
Output is correct |
4 |
Correct |
19 ms |
2136 KB |
Output is correct |
5 |
Correct |
22 ms |
2136 KB |
Output is correct |
6 |
Correct |
17 ms |
2192 KB |
Output is correct |
7 |
Correct |
19 ms |
2192 KB |
Output is correct |
8 |
Correct |
23 ms |
2192 KB |
Output is correct |
9 |
Correct |
22 ms |
2192 KB |
Output is correct |
10 |
Correct |
20 ms |
2192 KB |
Output is correct |
11 |
Correct |
27 ms |
2192 KB |
Output is correct |
12 |
Correct |
19 ms |
2192 KB |
Output is correct |
13 |
Correct |
19 ms |
2192 KB |
Output is correct |
14 |
Correct |
20 ms |
2192 KB |
Output is correct |
15 |
Correct |
20 ms |
2192 KB |
Output is correct |
16 |
Correct |
20 ms |
2192 KB |
Output is correct |
17 |
Correct |
21 ms |
2192 KB |
Output is correct |
18 |
Correct |
19 ms |
2272 KB |
Output is correct |
19 |
Correct |
19 ms |
2272 KB |
Output is correct |
20 |
Correct |
23 ms |
2272 KB |
Output is correct |
21 |
Correct |
22 ms |
2272 KB |
Output is correct |
22 |
Correct |
20 ms |
2272 KB |
Output is correct |
23 |
Correct |
20 ms |
2272 KB |
Output is correct |
24 |
Correct |
22 ms |
2272 KB |
Output is correct |
25 |
Correct |
19 ms |
2272 KB |
Output is correct |
26 |
Correct |
21 ms |
2272 KB |
Output is correct |
27 |
Correct |
20 ms |
2272 KB |
Output is correct |
28 |
Correct |
20 ms |
2272 KB |
Output is correct |
29 |
Correct |
23 ms |
2272 KB |
Output is correct |
30 |
Correct |
22 ms |
2272 KB |
Output is correct |
31 |
Correct |
23 ms |
2272 KB |
Output is correct |
32 |
Correct |
20 ms |
2272 KB |
Output is correct |
33 |
Correct |
22 ms |
2272 KB |
Output is correct |
34 |
Correct |
19 ms |
2272 KB |
Output is correct |
35 |
Correct |
24 ms |
2272 KB |
Output is correct |
36 |
Correct |
20 ms |
2272 KB |
Output is correct |
37 |
Correct |
22 ms |
2272 KB |
Output is correct |
38 |
Correct |
27 ms |
2272 KB |
Output is correct |
39 |
Correct |
23 ms |
2272 KB |
Output is correct |
40 |
Correct |
20 ms |
2272 KB |
Output is correct |
41 |
Correct |
19 ms |
2272 KB |
Output is correct |
42 |
Correct |
24 ms |
2272 KB |
Output is correct |
43 |
Correct |
20 ms |
2272 KB |
Output is correct |
44 |
Correct |
22 ms |
2272 KB |
Output is correct |
45 |
Correct |
17 ms |
2272 KB |
Output is correct |
46 |
Correct |
18 ms |
2272 KB |
Output is correct |
47 |
Correct |
20 ms |
2272 KB |
Output is correct |
48 |
Correct |
24 ms |
2272 KB |
Output is correct |
49 |
Correct |
21 ms |
2272 KB |
Output is correct |
50 |
Correct |
19 ms |
2272 KB |
Output is correct |