#include "Anyalib.h"
#include <bits/stdc++.h>
using namespace std;
static int getL;
namespace
{
const int Nmax = 1005;
vector<int> v[Nmax];
int n, w[Nmax], t[Nmax];
bool special[Nmax];
pair<int,int> edge[Nmax];
void dfs0(int node, int dad = -1)
{
w[node] = 0;
t[node] = dad;
for(auto it : v[node])
if(it != dad)
{
dfs0(it, node);
w[node] = max(w[it], w[node]);
}
if(w[node] == 9)
{
w[node] = 0;
special[node] = 1;
}
else ++w[node];
}
void dfs(int node, int dad, int C[])
{
for(auto it : v[node])
if(it != dad)
{
w[it] += w[node];
dfs(it, node, C);
}
}
};
void InitAnya(int N , int A[] , int B[])
{
n = N;
int i;
for(i=0; i<n-1; ++i)
{
v[A[i]].push_back(B[i]);
v[B[i]].push_back(A[i]);
edge[i] = {A[i], B[i]};
}
dfs0(0);
for(i=0; i<n-1; ++i)
if(t[edge[i].first] == edge[i].second) swap(edge[i].first, edge[i].second);
}
void Anya(int C[])
{
int i, j;
for(i=0; i<n; ++i) w[i] = 0;
for(i=0; i<n-1; ++i)
w[edge[i].second] += C[i];
for(i=1; i<n; ++i)
Save(i, w[i]);
dfs(0, -1, C);
int nr = n;
for(i=0; i<n; ++i)
if(special[i])
for(j=8; j>=0; --j)
{
Save(nr, (w[i] >> j) & 1);
++nr;
}
}
#include "Borislib.h"
#include <bits/stdc++.h>
using namespace std;
namespace
{
const int Nmax = 1005;
int n;
vector<int> v[Nmax];
int w[Nmax], where[Nmax], t[Nmax];
bool special[Nmax];
void dfs0(int node, int dad = -1)
{
w[node] = 0;
t[node] = dad;
for(auto it : v[node])
if(it != dad)
{
dfs0(it, node);
w[node] = max(w[it], w[node]);
}
if(w[node] == 9)
{
w[node] = 0;
special[node] = 1;
}
else ++w[node];
}
};
void InitBoris(int N , int A[] , int B[])
{
n = N;
int i;
for(i=0; i<n-1; ++i)
{
v[A[i]].push_back(B[i]);
v[B[i]].push_back(A[i]);
}
dfs0(0);
int nr = n;
for(i=0; i<n; ++i)
if(special[i])
{
where[i] = nr;
nr += 9;
}
}
int Boris(int x)
{
if(x == 0) return 0;
if(special[x])
{
int ans = 0, i;
for(i = where[x]; i < where[x] + 9; ++i)
ans = 2 * ans + Ask(i);
return ans;
}
return Ask(x) + Boris(t[x]);
}
Compilation message
Anya.cpp:6:12: warning: 'getL' defined but not used [-Wunused-variable]
6 | static int getL;
| ^~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
984 KB |
Output is correct |
2 |
Correct |
2 ms |
976 KB |
Output is correct |
3 |
Correct |
3 ms |
1096 KB |
Output is correct |
4 |
Correct |
5 ms |
1024 KB |
Output is correct |
5 |
Correct |
7 ms |
1280 KB |
Output is correct |
6 |
Correct |
7 ms |
1280 KB |
Output is correct |
7 |
Correct |
7 ms |
1280 KB |
Output is correct |
8 |
Correct |
7 ms |
1436 KB |
Output is correct |
9 |
Correct |
7 ms |
1280 KB |
Output is correct |
10 |
Correct |
10 ms |
1336 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
1280 KB |
Output is correct |
2 |
Correct |
8 ms |
1420 KB |
Output is correct |
3 |
Correct |
9 ms |
1376 KB |
Output is correct |
4 |
Correct |
8 ms |
1416 KB |
Output is correct |
5 |
Correct |
9 ms |
1280 KB |
Output is correct |
6 |
Correct |
8 ms |
1380 KB |
Output is correct |
7 |
Correct |
8 ms |
1416 KB |
Output is correct |
8 |
Correct |
9 ms |
1392 KB |
Output is correct |
9 |
Correct |
8 ms |
1280 KB |
Output is correct |
10 |
Correct |
9 ms |
1424 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
17 ms |
1720 KB |
Output is correct |
2 |
Correct |
17 ms |
1884 KB |
Output is correct |
3 |
Correct |
17 ms |
2120 KB |
Output is correct |
4 |
Correct |
17 ms |
1884 KB |
Output is correct |
5 |
Correct |
19 ms |
2016 KB |
Output is correct |
6 |
Correct |
19 ms |
1884 KB |
Output is correct |
7 |
Correct |
18 ms |
1884 KB |
Output is correct |
8 |
Correct |
25 ms |
1884 KB |
Output is correct |
9 |
Correct |
17 ms |
1792 KB |
Output is correct |
10 |
Correct |
22 ms |
1892 KB |
Output is correct |
11 |
Correct |
17 ms |
1880 KB |
Output is correct |
12 |
Correct |
24 ms |
1888 KB |
Output is correct |
13 |
Correct |
17 ms |
1792 KB |
Output is correct |
14 |
Correct |
17 ms |
1880 KB |
Output is correct |
15 |
Correct |
18 ms |
1888 KB |
Output is correct |
16 |
Correct |
17 ms |
1864 KB |
Output is correct |
17 |
Correct |
17 ms |
1864 KB |
Output is correct |
18 |
Correct |
17 ms |
1892 KB |
Output is correct |
19 |
Correct |
18 ms |
1864 KB |
Output is correct |
20 |
Correct |
17 ms |
1864 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
19 ms |
1584 KB |
Output is correct |
2 |
Correct |
17 ms |
1900 KB |
Output is correct |
3 |
Correct |
18 ms |
1856 KB |
Output is correct |
4 |
Correct |
18 ms |
2032 KB |
Output is correct |
5 |
Correct |
19 ms |
1892 KB |
Output is correct |
6 |
Correct |
16 ms |
1920 KB |
Output is correct |
7 |
Correct |
18 ms |
1792 KB |
Output is correct |
8 |
Correct |
16 ms |
1792 KB |
Output is correct |
9 |
Correct |
18 ms |
1892 KB |
Output is correct |
10 |
Correct |
17 ms |
1928 KB |
Output is correct |
11 |
Correct |
18 ms |
1792 KB |
Output is correct |
12 |
Correct |
18 ms |
1972 KB |
Output is correct |
13 |
Correct |
18 ms |
1792 KB |
Output is correct |
14 |
Correct |
18 ms |
1792 KB |
Output is correct |
15 |
Correct |
18 ms |
1904 KB |
Output is correct |
16 |
Correct |
16 ms |
1832 KB |
Output is correct |
17 |
Correct |
19 ms |
1900 KB |
Output is correct |
18 |
Correct |
18 ms |
1904 KB |
Output is correct |
19 |
Correct |
20 ms |
1912 KB |
Output is correct |
20 |
Correct |
18 ms |
1908 KB |
Output is correct |
21 |
Correct |
18 ms |
1908 KB |
Output is correct |
22 |
Correct |
19 ms |
1896 KB |
Output is correct |
23 |
Correct |
18 ms |
1792 KB |
Output is correct |
24 |
Correct |
18 ms |
1900 KB |
Output is correct |
25 |
Correct |
19 ms |
1908 KB |
Output is correct |
26 |
Correct |
18 ms |
1900 KB |
Output is correct |
27 |
Correct |
19 ms |
1924 KB |
Output is correct |
28 |
Correct |
18 ms |
1904 KB |
Output is correct |
29 |
Correct |
19 ms |
1904 KB |
Output is correct |
30 |
Correct |
18 ms |
2048 KB |
Output is correct |
31 |
Correct |
18 ms |
1896 KB |
Output is correct |
32 |
Correct |
16 ms |
1896 KB |
Output is correct |
33 |
Correct |
18 ms |
1792 KB |
Output is correct |
34 |
Correct |
16 ms |
1920 KB |
Output is correct |
35 |
Correct |
16 ms |
1792 KB |
Output is correct |
36 |
Correct |
18 ms |
1792 KB |
Output is correct |
37 |
Correct |
17 ms |
1792 KB |
Output is correct |
38 |
Correct |
18 ms |
1896 KB |
Output is correct |
39 |
Correct |
17 ms |
1924 KB |
Output is correct |
40 |
Correct |
16 ms |
1856 KB |
Output is correct |
41 |
Correct |
17 ms |
2048 KB |
Output is correct |
42 |
Correct |
16 ms |
1856 KB |
Output is correct |
43 |
Correct |
17 ms |
1856 KB |
Output is correct |
44 |
Correct |
16 ms |
1856 KB |
Output is correct |
45 |
Correct |
18 ms |
1912 KB |
Output is correct |
46 |
Correct |
18 ms |
1792 KB |
Output is correct |
47 |
Correct |
17 ms |
1916 KB |
Output is correct |
48 |
Correct |
17 ms |
1856 KB |
Output is correct |
49 |
Correct |
16 ms |
2044 KB |
Output is correct |
50 |
Correct |
16 ms |
1920 KB |
Output is correct |