#include "Joi.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAXN = 10010, MAXBIT = 60;
vector < int > adj[MAXN];
int used[MAXN], acord[MAXN];
vector < int > ord;
int last_bit;
void dfs(int v, ll X)
{
used[v] = 1;
acord[v] = last_bit;
/**if (last_bit == 59)
{
cout << "info " << (X & ((ll)(1) << last_bit)) << " " << ((X & ((ll)(1) << last_bit)) > 0) << endl;
}*/
///cout << "Vertex " << v << " " << last_bit << endl;
MessageBoard(v, ((X & ((ll)(1) << last_bit)) > 0));
last_bit ++;
if (last_bit == MAXBIT)
last_bit = 0;
ord.push_back(v);
for (int u : adj[v])
{
if (used[u])
continue;
dfs(u, X);
ord.push_back(v);
}
}
void build_tree(int N, int M, int A[], int B[], ll X)
{
for (int i = M - 1; i >= 0; i --)
{
adj[A[i]].push_back(B[i]);
adj[B[i]].push_back(A[i]);
}
dfs(0, X);
ord.pop_back();
}
void Joi(int N, int M, int A[], int B[], long long X, int T) {
build_tree(N, M, A, B, X);
}
#include "Ioi.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAXN = 10010, MAXBIT = 60;
vector < int > graph[MAXN];
int marked[MAXN], linked[MAXN];
vector < int > path;
int next_bit;
void dfs(int v)
{
marked[v] = 1;
linked[v] = next_bit ++;
if (next_bit == MAXBIT)
next_bit = 0;
//MessageBoard(v, ((X & ((ll)(1) << bit)) > 0));
path.push_back(v);
for (int u : graph[v])
{
if (marked[u])
continue;
dfs(u);
path.push_back(v);
}
}
void build_tree(int N, int M, int A[], int B[])
{
for (int i = M - 1; i >= 0; i --)
{
graph[A[i]].push_back(B[i]);
graph[B[i]].push_back(A[i]);
}
dfs(0);
path.pop_back();
}
int bit_val[MAXBIT], ch[MAXBIT];
int min_step[MAXN], from[MAXN];
long long Ioi(int N, int M, int A[], int B[], int P, int V, int T)
{
build_tree(N, M, A, B);
int pos = 0;
while(path[pos] != P)
pos ++;
vector < int > tk = path;
for (int cur : tk)
path.push_back(cur);
/**for (int cur : path)
cout << cur << " ";
cout << endl;*/
bit_val[linked[P]] = V;
ch[linked[P]] = 1;
int ver = P;
for (int i = 0; i < N; i ++)
{
min_step[i] = 4 * N;
from[i] = -1;
}
for (int s = 0; s < tk.size(); s ++)
{
ll ds = 0;
int pivot = s;
while(pivot < path.size())
{
//cout << s << " : " << pivot << " " << ds << " " << endl;
ds |= ((ll)(1) << linked[path[pivot]]);
if (ds == ((ll)(1) << MAXBIT) - 1)
break;
pivot ++;
}
assert(pivot < path.size());
if (pivot - s < min_step[path[s]])
{
from[path[s]] = s;
min_step[path[s]] = pivot - s;
}
}
ll ds = 0;
bool done = false;
int best_to = -1, best_val = 300;
for (int to = 0; to < 120; to ++)
{
if (to + min_step[path[pos + to]] <= best_val)
{
best_val = to + min_step[path[pos + to]];
best_to = to;
}
}
assert(best_to != - 1);
int to = best_to;
for (int d = 1; d <= to; d ++)
{
bit_val[linked[path[pos + d]]] = Move(path[pos + d]);
ch[linked[path[pos + d]]] = 1;
///cout << "add " << linked[path[pos + d]];
}
ver = path[pos + to];
for (int d = 1; d <= min_step[ver]; d ++)
{
bit_val[linked[path[from[ver] + d]]] = Move(path[from[ver] + d]);
ch[linked[path[from[ver] + d]]] = 1;
///cout << "add " << linked[path[from[ver] + d]] << endl;
}
done = true;
/*
for (int step = 0; ds != ((ll)(1) << MAXBIT) - 1; step ++)
{
int nxt = (pos + 1) % (int)(path.size());
//cout << "move from " << ver << " " << path[nxt] << endl;
ver = path[nxt];
int res = Move(ver);
///assert(step != 119);
//cout << "linked " << linked[ver] << " " << res << endl;
bit_val[linked[ver]] = res;
ch[linked[ver]] = 1;
ds |= ((ll)(1) << linked[ver]);
pos = nxt;
}*/
ll X = 0;
for (int bit = 0; bit < MAXBIT; bit ++)
{
//if (ch[bit] == 0)
//cout << "FUCK " << bit << endl;
assert(ch[bit]);
if (bit_val[bit] > 0)
X |= ((ll)(1) << bit);
}
//cout << "X " << X << endl;
return X;
}
Compilation message
Ioi.cpp: In function 'long long int Ioi(int, int, int*, int*, int, int, int)':
Ioi.cpp:73:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
73 | for (int s = 0; s < tk.size(); s ++)
| ~~^~~~~~~~~~~
Ioi.cpp:77:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
77 | while(pivot < path.size())
| ~~~~~~^~~~~~~~~~~~~
In file included from /usr/include/c++/10/cassert:44,
from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:33,
from Ioi.cpp:3:
Ioi.cpp:86:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
86 | assert(pivot < path.size());
| ~~~~~~^~~~~~~~~~~~~
Ioi.cpp:94:6: warning: unused variable 'ds' [-Wunused-variable]
94 | ll ds = 0;
| ^~
Ioi.cpp:95:8: warning: variable 'done' set but not used [-Wunused-but-set-variable]
95 | bool done = false;
| ^~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
1300 KB |
Output is correct |
2 |
Correct |
1 ms |
1312 KB |
Output is correct |
3 |
Correct |
0 ms |
1316 KB |
Output is correct |
4 |
Correct |
0 ms |
1312 KB |
Output is correct |
5 |
Correct |
1 ms |
1312 KB |
Output is correct |
6 |
Correct |
1 ms |
1308 KB |
Output is correct |
7 |
Correct |
1 ms |
1556 KB |
Output is correct |
8 |
Correct |
2 ms |
1308 KB |
Output is correct |
9 |
Correct |
1 ms |
1312 KB |
Output is correct |
10 |
Correct |
1 ms |
1552 KB |
Output is correct |
11 |
Correct |
3 ms |
1636 KB |
Output is correct |
12 |
Correct |
1 ms |
1308 KB |
Output is correct |
13 |
Correct |
1 ms |
1308 KB |
Output is correct |
14 |
Correct |
2 ms |
1316 KB |
Output is correct |
15 |
Correct |
0 ms |
1312 KB |
Output is correct |
16 |
Correct |
1 ms |
1316 KB |
Output is correct |
17 |
Correct |
1 ms |
1316 KB |
Output is correct |
18 |
Correct |
1 ms |
1308 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
18 ms |
5160 KB |
Output is correct |
2 |
Correct |
18 ms |
5288 KB |
Output is correct |
3 |
Correct |
20 ms |
5492 KB |
Output is correct |
4 |
Correct |
11 ms |
3652 KB |
Output is correct |
5 |
Correct |
11 ms |
4168 KB |
Output is correct |
6 |
Correct |
14 ms |
4028 KB |
Output is correct |
7 |
Correct |
18 ms |
4104 KB |
Output is correct |
8 |
Correct |
15 ms |
4140 KB |
Output is correct |
9 |
Correct |
11 ms |
4160 KB |
Output is correct |
10 |
Correct |
13 ms |
3660 KB |
Output is correct |
11 |
Correct |
13 ms |
3648 KB |
Output is correct |
12 |
Correct |
12 ms |
3628 KB |
Output is correct |
13 |
Correct |
10 ms |
3628 KB |
Output is correct |
14 |
Correct |
11 ms |
3636 KB |
Output is correct |
15 |
Correct |
11 ms |
3900 KB |
Output is correct |
16 |
Correct |
11 ms |
3644 KB |
Output is correct |
17 |
Correct |
11 ms |
3652 KB |
Output is correct |
18 |
Correct |
11 ms |
3656 KB |
Output is correct |
19 |
Correct |
13 ms |
3652 KB |
Output is correct |
20 |
Correct |
9 ms |
4164 KB |
Output is correct |
21 |
Correct |
9 ms |
4176 KB |
Output is correct |
22 |
Correct |
11 ms |
4028 KB |
Output is correct |
23 |
Correct |
16 ms |
4140 KB |
Output is correct |
24 |
Correct |
13 ms |
4036 KB |
Output is correct |
25 |
Correct |
12 ms |
4032 KB |
Output is correct |
26 |
Correct |
13 ms |
4164 KB |
Output is correct |
27 |
Correct |
18 ms |
4168 KB |
Output is correct |
28 |
Correct |
13 ms |
4164 KB |
Output is correct |
29 |
Correct |
14 ms |
4004 KB |
Output is correct |
30 |
Correct |
11 ms |
4020 KB |
Output is correct |
31 |
Correct |
1 ms |
1308 KB |
Output is correct |
32 |
Correct |
1 ms |
1380 KB |
Output is correct |
33 |
Correct |
1 ms |
1308 KB |
Output is correct |
34 |
Correct |
0 ms |
1312 KB |
Output is correct |
35 |
Correct |
1 ms |
1300 KB |
Output is correct |
36 |
Correct |
1 ms |
1300 KB |
Output is correct |
37 |
Correct |
1 ms |
1308 KB |
Output is correct |
38 |
Correct |
0 ms |
1312 KB |
Output is correct |
39 |
Correct |
1 ms |
1304 KB |
Output is correct |
40 |
Correct |
0 ms |
1296 KB |
Output is correct |
41 |
Correct |
1 ms |
1300 KB |
Output is correct |
42 |
Correct |
1 ms |
1300 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
1300 KB |
Output is correct |
2 |
Correct |
1 ms |
1312 KB |
Output is correct |
3 |
Correct |
1 ms |
1300 KB |
Output is correct |
4 |
Correct |
3 ms |
1856 KB |
Output is correct |
5 |
Correct |
2 ms |
1864 KB |
Output is correct |
6 |
Correct |
2 ms |
1868 KB |
Output is correct |
7 |
Correct |
2 ms |
1860 KB |
Output is correct |
8 |
Correct |
2 ms |
1848 KB |
Output is correct |
9 |
Correct |
10 ms |
4932 KB |
Output is correct |
10 |
Correct |
12 ms |
4928 KB |
Output is correct |
11 |
Correct |
9 ms |
4860 KB |
Output is correct |
12 |
Correct |
0 ms |
1304 KB |
Output is correct |
13 |
Correct |
1 ms |
1312 KB |
Output is correct |
14 |
Correct |
1 ms |
1312 KB |
Output is correct |
15 |
Correct |
2 ms |
1312 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
20 ms |
5284 KB |
Output is correct |
2 |
Correct |
19 ms |
5396 KB |
Output is correct |
3 |
Correct |
18 ms |
5288 KB |
Output is correct |
4 |
Correct |
11 ms |
3656 KB |
Output is correct |
5 |
Partially correct |
15 ms |
4536 KB |
Partially correct |
6 |
Correct |
13 ms |
4164 KB |
Output is correct |
7 |
Correct |
12 ms |
4164 KB |
Output is correct |
8 |
Correct |
14 ms |
4032 KB |
Output is correct |
9 |
Correct |
12 ms |
4036 KB |
Output is correct |
10 |
Correct |
11 ms |
3628 KB |
Output is correct |
11 |
Correct |
11 ms |
3656 KB |
Output is correct |
12 |
Correct |
15 ms |
3500 KB |
Output is correct |
13 |
Correct |
11 ms |
3500 KB |
Output is correct |
14 |
Correct |
16 ms |
3640 KB |
Output is correct |
15 |
Correct |
11 ms |
3652 KB |
Output is correct |
16 |
Correct |
11 ms |
3652 KB |
Output is correct |
17 |
Correct |
13 ms |
3660 KB |
Output is correct |
18 |
Correct |
13 ms |
3656 KB |
Output is correct |
19 |
Correct |
11 ms |
3656 KB |
Output is correct |
20 |
Correct |
11 ms |
4292 KB |
Output is correct |
21 |
Correct |
14 ms |
4160 KB |
Output is correct |
22 |
Correct |
14 ms |
4168 KB |
Output is correct |
23 |
Correct |
12 ms |
4040 KB |
Output is correct |
24 |
Correct |
14 ms |
4032 KB |
Output is correct |
25 |
Correct |
13 ms |
4172 KB |
Output is correct |
26 |
Correct |
13 ms |
4160 KB |
Output is correct |
27 |
Correct |
13 ms |
4172 KB |
Output is correct |
28 |
Correct |
13 ms |
4032 KB |
Output is correct |
29 |
Correct |
11 ms |
4020 KB |
Output is correct |
30 |
Correct |
12 ms |
4524 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
19 ms |
5288 KB |
Output is correct |
2 |
Correct |
24 ms |
5488 KB |
Output is correct |
3 |
Correct |
25 ms |
5280 KB |
Output is correct |
4 |
Correct |
13 ms |
3648 KB |
Output is correct |
5 |
Incorrect |
11 ms |
4688 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |