#include "Joi.h"
#include <memory.h>
#include <vector>
using namespace std;
int wpos[10000];
vector<int> jedge[10000];
vector<int> jg[10000];
int jp[10000][15],jd[10000];
//climb
//lca
//dist
int jclimb(int x,int d) {
int step = 0;
while (d) {
if (d & 1) x = jp[x][step];
d >>= 1;
++step;
}
return x;
}
int jlca(int a,int b) {
if (jd[a] < jd[b]) b = jclimb(b,jd[b]-jd[a]);
else if (jd[a] > jd[b]) a = jclimb(a,jd[a]-jd[b]);
if (a == b) return a;
for (int j = 14; j >= 0; --j) {
if (jp[a][j] != jp[b][j]) {
a = jp[a][j];
b = jp[b][j];
}
}
return jp[a][0];
}
inline int jdist(int a,int b) {
return jd[a] + jd[b] - (jd[jlca(a,b)]<<1);
}
void make_jtree(int x,vector<int> &g) {//init dfs
if (g.size() < 60) g.push_back(x);
wpos[x] = -1;
for (auto to : jedge[x]) {
if (wpos[to] < 0) continue;
jd[to] = jd[x] + 1;
jp[to][0] = x;
make_jtree(to, g);
}
}
void jdfs(int x) {
if (wpos[x]!=-1) return;
int p = jp[x][0];
jdfs(p);
jg[x] = jg[p];
int mx = 0;
int rep = 0;
for (int i = 0; i < jg[x].size(); ++i) {
if (jg[x][i] == p) continue;
int dist = jdist(x,jg[x][i]);
if (dist >mx) {
mx = dist;
rep = i;
}
}
wpos[x] = wpos[jg[x][rep]];
jg[x][rep] = x;
}
void Joi(int N, int M, int A[], int B[], long long X, int T) {
memset(jp,-1,sizeof(jp));
for (int i = 0; i < M; ++i) {
jedge[A[i]].push_back(B[i]);
jedge[B[i]].push_back(A[i]);
}
make_jtree(0,jg[0]);
for (int i = 0; i < jg[0].size(); ++i) {
int x = jg[0][i];
jg[x] = jg[0];
wpos[x] = i;
}
for (int j = 1; j < 15; ++j) for (int i = 0; i < N; ++i) jp[i][j] = jp[jp[i][j - 1]][j - 1];
for (int i = 0; i < N; ++i) {
jdfs(i);
MessageBoard(i,(X>>wpos[i])&1);
}
}
#include "Ioi.h"
#include <vector>
#include <memory.h>
using namespace std;
int rpos[10000];
vector<int> iedge[10000];
vector<int> ig[10000];
int ip[10000][15], id[10000];
int vis[10000];
int iclimb(int x, int d) {
int step = 0;
while (d) {
if (d & 1) x = ip[x][step];
d >>= 1;
++step;
}
return x;
}
int ilca(int a, int b) {
if (id[a] < id[b]) b = iclimb(b, id[b] - id[a]);
else if (id[a] > id[b]) a = iclimb(a, id[a] - id[b]);
if (a == b) return a;
for (int j = 14; j >= 0; --j) {
if (ip[a][j] != ip[b][j]) {
a = ip[a][j];
b = ip[b][j];
}
}
return ip[a][0];
}
inline int idist(int a, int b) {
return id[a] + id[b] - (id[ilca(a, b)] << 1);
}
void make_itree(int x, vector<int> &g) {//init dfs
if (g.size() < 60) g.push_back(x);
rpos[x] = -1;
for (int i = 0; i < iedge[x].size(); ++i) {
int to = iedge[x][i];
if (rpos[to] < 0) {
iedge[x][i] = -1;
continue;
}
id[to] = id[x] + 1;
ip[to][0] = x;
make_itree(to, g);
}
}
void idfs(int x) {
if (rpos[x] != -1) return;
int p = ip[x][0];
idfs(p);
ig[x] = ig[p];
int mx = 0;
int rep = 0;
for (int i = 0; i < ig[x].size(); ++i) {
if (ig[x][i] == p) continue;
int dist = idist(x, ig[x][i]);
if (dist > mx) {
mx = dist;
rep = i;
}
}
rpos[x] = rpos[ig[x][rep]];
ig[x][rep] = x;
}
long long cage(int x,int from) {
long long mem = 0;
//printf("dfs:%d\n",x);
for (auto to : iedge[x]) {
if (to < 0 || to==from) continue;
if (!vis[to]) continue;
long long r = Move(to);
mem |= (r <<rpos[to]);
mem |= cage(to,x);
//printf("dfs:%d\n", x);
}
int p = ip[x][0];
if (p>=0 && vis[p] && p!=from) {
int p = ip[x][0];
long long r = Move(p);
mem |= (r << rpos[p]);
mem |= cage(p,x);
//printf("dfs:%d\n", x);
}
vis[x] = 0;
if (from >= 0) {
long long r = Move(from);
mem |= (r << rpos[from]);
}
return mem;
}
long long Ioi(int N, int M, int A[], int B[], int P, int V, int T) {
memset(ip, -1, sizeof(ip));
for (int i = 0; i < M; ++i) {
iedge[A[i]].push_back(B[i]);
iedge[B[i]].push_back(A[i]);
}
make_itree(0, ig[0]);
for (int i = 0; i < ig[0].size(); ++i) {
int x = ig[0][i];
ig[x] = ig[0];
rpos[x] = i;
}
for (int j = 1; j < 15; ++j) for (int i = 0; i < N; ++i) ip[i][j] = ip[ip[i][j - 1]][j - 1];
idfs(P);
for (auto x : ig[P]) vis[x] = 1;
return cage(P, -1);
}
Compilation message
Joi.cpp: In function 'void jdfs(int)':
Joi.cpp:53:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i = 0; i < jg[x].size(); ++i) {
~~^~~~~~~~~~~~~~
Joi.cpp: In function 'void Joi(int, int, int*, int*, long long int, int)':
Joi.cpp:71:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i = 0; i < jg[0].size(); ++i) {
~~^~~~~~~~~~~~~~
Ioi.cpp: In function 'void make_itree(int, std::vector<int>&)':
Ioi.cpp:38:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i = 0; i < iedge[x].size(); ++i) {
~~^~~~~~~~~~~~~~~~~
Ioi.cpp: In function 'void idfs(int)':
Ioi.cpp:59:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i = 0; i < ig[x].size(); ++i) {
~~^~~~~~~~~~~~~~
Ioi.cpp: In function 'long long int Ioi(int, int, int*, int*, int, int, int)':
Ioi.cpp:103:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i = 0; i < ig[0].size(); ++i) {
~~^~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
2800 KB |
Output is correct |
2 |
Correct |
7 ms |
2936 KB |
Output is correct |
3 |
Correct |
7 ms |
3076 KB |
Output is correct |
4 |
Correct |
6 ms |
2992 KB |
Output is correct |
5 |
Correct |
6 ms |
2988 KB |
Output is correct |
6 |
Correct |
6 ms |
3068 KB |
Output is correct |
7 |
Correct |
7 ms |
3200 KB |
Output is correct |
8 |
Correct |
7 ms |
3152 KB |
Output is correct |
9 |
Correct |
6 ms |
3280 KB |
Output is correct |
10 |
Correct |
6 ms |
2944 KB |
Output is correct |
11 |
Correct |
9 ms |
3400 KB |
Output is correct |
12 |
Correct |
6 ms |
2940 KB |
Output is correct |
13 |
Correct |
7 ms |
3068 KB |
Output is correct |
14 |
Correct |
7 ms |
3076 KB |
Output is correct |
15 |
Correct |
7 ms |
3204 KB |
Output is correct |
16 |
Correct |
7 ms |
3152 KB |
Output is correct |
17 |
Correct |
7 ms |
3080 KB |
Output is correct |
18 |
Correct |
7 ms |
3076 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
48 ms |
10736 KB |
Output is correct |
2 |
Correct |
57 ms |
10736 KB |
Output is correct |
3 |
Correct |
50 ms |
10736 KB |
Output is correct |
4 |
Correct |
53 ms |
9200 KB |
Output is correct |
5 |
Correct |
42 ms |
9712 KB |
Output is correct |
6 |
Correct |
48 ms |
9712 KB |
Output is correct |
7 |
Correct |
43 ms |
9712 KB |
Output is correct |
8 |
Correct |
50 ms |
9968 KB |
Output is correct |
9 |
Correct |
54 ms |
9712 KB |
Output is correct |
10 |
Correct |
46 ms |
9456 KB |
Output is correct |
11 |
Correct |
47 ms |
9248 KB |
Output is correct |
12 |
Correct |
46 ms |
8688 KB |
Output is correct |
13 |
Correct |
47 ms |
8688 KB |
Output is correct |
14 |
Correct |
49 ms |
9000 KB |
Output is correct |
15 |
Correct |
53 ms |
9456 KB |
Output is correct |
16 |
Correct |
54 ms |
9456 KB |
Output is correct |
17 |
Correct |
57 ms |
9200 KB |
Output is correct |
18 |
Correct |
58 ms |
9456 KB |
Output is correct |
19 |
Correct |
55 ms |
9512 KB |
Output is correct |
20 |
Correct |
31 ms |
9712 KB |
Output is correct |
21 |
Correct |
31 ms |
9720 KB |
Output is correct |
22 |
Correct |
45 ms |
9712 KB |
Output is correct |
23 |
Correct |
49 ms |
10064 KB |
Output is correct |
24 |
Correct |
47 ms |
9712 KB |
Output is correct |
25 |
Correct |
48 ms |
9968 KB |
Output is correct |
26 |
Correct |
46 ms |
9968 KB |
Output is correct |
27 |
Correct |
46 ms |
9968 KB |
Output is correct |
28 |
Correct |
48 ms |
10224 KB |
Output is correct |
29 |
Correct |
45 ms |
9112 KB |
Output is correct |
30 |
Correct |
46 ms |
9456 KB |
Output is correct |
31 |
Correct |
6 ms |
3136 KB |
Output is correct |
32 |
Correct |
6 ms |
2932 KB |
Output is correct |
33 |
Correct |
6 ms |
3068 KB |
Output is correct |
34 |
Correct |
6 ms |
3068 KB |
Output is correct |
35 |
Correct |
6 ms |
2932 KB |
Output is correct |
36 |
Correct |
6 ms |
2940 KB |
Output is correct |
37 |
Correct |
6 ms |
2968 KB |
Output is correct |
38 |
Correct |
6 ms |
2940 KB |
Output is correct |
39 |
Correct |
6 ms |
2940 KB |
Output is correct |
40 |
Correct |
6 ms |
2940 KB |
Output is correct |
41 |
Correct |
6 ms |
2960 KB |
Output is correct |
42 |
Correct |
6 ms |
2940 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
2936 KB |
Output is correct |
2 |
Correct |
6 ms |
3068 KB |
Output is correct |
3 |
Correct |
6 ms |
3088 KB |
Output is correct |
4 |
Correct |
8 ms |
4080 KB |
Output is correct |
5 |
Correct |
9 ms |
4072 KB |
Output is correct |
6 |
Correct |
8 ms |
4080 KB |
Output is correct |
7 |
Correct |
9 ms |
4080 KB |
Output is correct |
8 |
Correct |
10 ms |
4128 KB |
Output is correct |
9 |
Correct |
34 ms |
10480 KB |
Output is correct |
10 |
Correct |
28 ms |
10480 KB |
Output is correct |
11 |
Correct |
39 ms |
10880 KB |
Output is correct |
12 |
Correct |
6 ms |
2980 KB |
Output is correct |
13 |
Correct |
6 ms |
2972 KB |
Output is correct |
14 |
Correct |
6 ms |
2940 KB |
Output is correct |
15 |
Correct |
6 ms |
3000 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
53 ms |
10736 KB |
Output is correct |
2 |
Correct |
56 ms |
10992 KB |
Output is correct |
3 |
Correct |
53 ms |
10992 KB |
Output is correct |
4 |
Correct |
54 ms |
9456 KB |
Output is correct |
5 |
Correct |
45 ms |
9968 KB |
Output is correct |
6 |
Correct |
51 ms |
9632 KB |
Output is correct |
7 |
Correct |
53 ms |
9968 KB |
Output is correct |
8 |
Correct |
43 ms |
9712 KB |
Output is correct |
9 |
Correct |
47 ms |
9968 KB |
Output is correct |
10 |
Correct |
49 ms |
9712 KB |
Output is correct |
11 |
Correct |
50 ms |
9672 KB |
Output is correct |
12 |
Correct |
45 ms |
9040 KB |
Output is correct |
13 |
Correct |
49 ms |
8944 KB |
Output is correct |
14 |
Correct |
49 ms |
9200 KB |
Output is correct |
15 |
Correct |
48 ms |
9456 KB |
Output is correct |
16 |
Correct |
52 ms |
9456 KB |
Output is correct |
17 |
Correct |
53 ms |
9456 KB |
Output is correct |
18 |
Correct |
53 ms |
9456 KB |
Output is correct |
19 |
Correct |
55 ms |
9456 KB |
Output is correct |
20 |
Correct |
32 ms |
9912 KB |
Output is correct |
21 |
Correct |
31 ms |
9968 KB |
Output is correct |
22 |
Correct |
48 ms |
9968 KB |
Output is correct |
23 |
Correct |
46 ms |
9968 KB |
Output is correct |
24 |
Correct |
48 ms |
9968 KB |
Output is correct |
25 |
Correct |
47 ms |
9976 KB |
Output is correct |
26 |
Correct |
46 ms |
9968 KB |
Output is correct |
27 |
Correct |
49 ms |
9968 KB |
Output is correct |
28 |
Correct |
46 ms |
9712 KB |
Output is correct |
29 |
Correct |
45 ms |
9400 KB |
Output is correct |
30 |
Correct |
46 ms |
9456 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
50 ms |
10992 KB |
Output is correct |
2 |
Correct |
49 ms |
10992 KB |
Output is correct |
3 |
Correct |
51 ms |
10992 KB |
Output is correct |
4 |
Correct |
57 ms |
9640 KB |
Output is correct |
5 |
Correct |
41 ms |
10480 KB |
Output is correct |
6 |
Correct |
47 ms |
9672 KB |
Output is correct |
7 |
Correct |
46 ms |
9712 KB |
Output is correct |
8 |
Correct |
53 ms |
9712 KB |
Output is correct |
9 |
Correct |
48 ms |
9696 KB |
Output is correct |
10 |
Correct |
47 ms |
9320 KB |
Output is correct |
11 |
Correct |
47 ms |
9456 KB |
Output is correct |
12 |
Correct |
46 ms |
8944 KB |
Output is correct |
13 |
Correct |
47 ms |
8944 KB |
Output is correct |
14 |
Correct |
48 ms |
9200 KB |
Output is correct |
15 |
Correct |
57 ms |
9456 KB |
Output is correct |
16 |
Correct |
50 ms |
9456 KB |
Output is correct |
17 |
Correct |
56 ms |
9456 KB |
Output is correct |
18 |
Correct |
55 ms |
9656 KB |
Output is correct |
19 |
Correct |
54 ms |
9712 KB |
Output is correct |
20 |
Correct |
31 ms |
9968 KB |
Output is correct |
21 |
Correct |
31 ms |
9968 KB |
Output is correct |
22 |
Correct |
48 ms |
9968 KB |
Output is correct |
23 |
Correct |
48 ms |
9968 KB |
Output is correct |
24 |
Correct |
47 ms |
9968 KB |
Output is correct |
25 |
Correct |
48 ms |
9968 KB |
Output is correct |
26 |
Correct |
46 ms |
9720 KB |
Output is correct |
27 |
Correct |
50 ms |
10104 KB |
Output is correct |
28 |
Correct |
49 ms |
9976 KB |
Output is correct |
29 |
Correct |
44 ms |
9712 KB |
Output is correct |
30 |
Correct |
46 ms |
9968 KB |
Output is correct |
31 |
Correct |
6 ms |
2940 KB |
Output is correct |
32 |
Correct |
6 ms |
2964 KB |
Output is correct |
33 |
Correct |
6 ms |
3060 KB |
Output is correct |
34 |
Correct |
6 ms |
2952 KB |
Output is correct |
35 |
Correct |
6 ms |
2932 KB |
Output is correct |
36 |
Correct |
6 ms |
2968 KB |
Output is correct |
37 |
Correct |
5 ms |
2932 KB |
Output is correct |
38 |
Correct |
6 ms |
2976 KB |
Output is correct |
39 |
Correct |
6 ms |
3008 KB |
Output is correct |
40 |
Correct |
5 ms |
2808 KB |
Output is correct |
41 |
Correct |
6 ms |
2960 KB |
Output is correct |
42 |
Correct |
5 ms |
2804 KB |
Output is correct |