#include "Joi.h"
#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> pii;
#define MAX 10101
#define LEN 60
namespace JOI {
vector<int> adj[MAX];
vector<int> tree[MAX];
queue<int> q;
int cnt = 0;
int col[MAX];
int ans[MAX];
int num[MAX];
int vis[MAX];
int prt[MAX];
void dfs(int x, int p, int c) {
col[x] = c;
ans[x] = ++cnt;
for (auto v : tree[x]) if (p != v) {
if (cnt < LEN) dfs(v, x, c);
else q.push(v);
}
}
void getnum(int x, int p = -1) {
if (~p) tree[p].push_back(x), tree[x].push_back(p), prt[x] = p;
num[x] = 1;
vis[x] = 1;
for (auto v : adj[x]) if (!vis[v]) {
getnum(v, x);
num[x] += num[v];
}
}
vector<int> lst;
void make_lst(int x, int p, int c) {
for (auto v : tree[x]) if (v != p && col[v] == c) make_lst(v, x, c);
lst.push_back(x);
}
void color_rem(int x, int p, int c) {
ans[x] = ans[lst.back()];
lst.pop_back();
col[x] = c;
for (auto v : tree[x]) if (v != p) color_rem(v, x, c);
}
}
void Joi(int N, int M, int A[], int B[], long long X, int T) {
int i;
for (i = 0; i < M; i++) JOI::adj[A[i]].push_back(B[i]), JOI::adj[B[i]].push_back(A[i]);
JOI::getnum(0);
JOI::q.push(0);
int cols = 0;
vector<int> rem;
while (JOI::q.size()) {
int t = JOI::q.front();
JOI::q.pop();
if (JOI::num[t] < LEN) rem.push_back(t);
else JOI::cnt = 0, JOI::dfs(t, JOI::prt[t], ++cols);
}
for (auto v : rem) {
cols++;
JOI::make_lst(JOI::prt[v], -1, JOI::col[JOI::prt[v]]);
reverse(JOI::lst.begin(), JOI::lst.end());
JOI::color_rem(v, JOI::prt[v], cols);
JOI::lst.clear();
}
for (i = 0; i < N; i++) MessageBoard(i, (X >> (JOI::ans[i] - 1)) & 1ll);
}
#include "Ioi.h"
#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> pii;
typedef long long ll;
#define MAX 10101
#define LEN 60
namespace IOI {
vector<int> adj[MAX];
vector<int> tree[MAX];
queue<int> q;
int cnt = 0;
int col[MAX];
int ans[MAX];
int num[MAX];
int vis[MAX];
int prt[MAX];
void dfs(int x, int p, int c) {
col[x] = c;
ans[x] = ++cnt;
for (auto v : tree[x]) if (p != v) {
if (cnt < LEN) dfs(v, x, c);
else q.push(v);
}
}
void getnum(int x, int p = -1) {
if (~p) tree[p].push_back(x), tree[x].push_back(p), prt[x] = p;
num[x] = 1;
vis[x] = 1;
for (auto v : adj[x]) if (!vis[v]) {
getnum(v, x);
num[x] += num[v];
}
}
vector<int> lst;
void make_lst(int x, int p, int c) {
for (auto v : tree[x]) if (v != p && col[v] == c) make_lst(v, x, c);
lst.push_back(x);
}
void color_rem(int x, int p, int c) {
ans[x] = ans[lst.back()];
lst.pop_back();
col[x] = c;
for (auto v : tree[x]) if (v != p) color_rem(v, x, c);
}
vector<int> rems[MAX];
int chk[MAX];
int Xs[MAX];
void getans(int x, int p = -1) {
for (auto v : tree[x]) if (v != p && chk[v]) {
Xs[ans[v] - 1] = Move(v);
getans(v, x);
Move(x);
}
}
}
long long Ioi(int N, int M, int A[], int B[], int P, int V, int T) {
int i;
for (i = 0; i < M; i++) IOI::adj[A[i]].push_back(B[i]), IOI::adj[B[i]].push_back(A[i]);
IOI::getnum(0);
IOI::q.push(0);
int cols = 0;
vector<int> rem;
while (IOI::q.size()) {
int t = IOI::q.front();
IOI::q.pop();
if (IOI::num[t] < LEN) rem.push_back(t);
else IOI::cnt = 0, IOI::dfs(t, IOI::prt[t], ++cols);
}
int x = cols;
for (auto v : rem) {
cols++;
IOI::make_lst(IOI::prt[v], -1, IOI::col[IOI::prt[v]]);
reverse(IOI::lst.begin(), IOI::lst.end());
IOI::color_rem(v, IOI::prt[v], cols);
swap(IOI::lst, IOI::rems[cols]);
IOI::lst.clear();
}
int C = IOI::col[P];
for (i = 0; i < N; i++) if (IOI::col[i] == C) IOI::chk[i] = 1;
for (auto v : IOI::rems[C]) IOI::chk[v] = 1;
IOI::Xs[IOI::ans[P] - 1] = V;
IOI::getans(P);
ll X = 0;
for (i = 0; i < LEN; i++) X |= (ll)IOI::Xs[i] << (ll)i;
return X;
}
Compilation message
Ioi.cpp: In function 'long long int Ioi(int, int, int*, int*, int, int, int)':
Ioi.cpp:71:6: warning: unused variable 'x' [-Wunused-variable]
71 | int x = cols;
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
1796 KB |
Output is correct |
2 |
Correct |
2 ms |
1796 KB |
Output is correct |
3 |
Correct |
2 ms |
1928 KB |
Output is correct |
4 |
Correct |
2 ms |
1800 KB |
Output is correct |
5 |
Correct |
2 ms |
1796 KB |
Output is correct |
6 |
Correct |
2 ms |
1796 KB |
Output is correct |
7 |
Correct |
2 ms |
2064 KB |
Output is correct |
8 |
Correct |
2 ms |
2056 KB |
Output is correct |
9 |
Correct |
2 ms |
2004 KB |
Output is correct |
10 |
Correct |
2 ms |
1804 KB |
Output is correct |
11 |
Correct |
5 ms |
2212 KB |
Output is correct |
12 |
Correct |
2 ms |
1796 KB |
Output is correct |
13 |
Correct |
2 ms |
1936 KB |
Output is correct |
14 |
Correct |
2 ms |
1880 KB |
Output is correct |
15 |
Correct |
2 ms |
1928 KB |
Output is correct |
16 |
Correct |
2 ms |
1868 KB |
Output is correct |
17 |
Correct |
2 ms |
1924 KB |
Output is correct |
18 |
Correct |
2 ms |
1888 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
26 ms |
5968 KB |
Output is correct |
2 |
Correct |
26 ms |
6332 KB |
Output is correct |
3 |
Correct |
27 ms |
6320 KB |
Output is correct |
4 |
Correct |
18 ms |
4760 KB |
Output is correct |
5 |
Correct |
18 ms |
5116 KB |
Output is correct |
6 |
Correct |
18 ms |
5240 KB |
Output is correct |
7 |
Correct |
18 ms |
5264 KB |
Output is correct |
8 |
Correct |
17 ms |
5268 KB |
Output is correct |
9 |
Correct |
20 ms |
5340 KB |
Output is correct |
10 |
Correct |
150 ms |
7128 KB |
Output is correct |
11 |
Correct |
166 ms |
7032 KB |
Output is correct |
12 |
Correct |
14 ms |
4292 KB |
Output is correct |
13 |
Correct |
14 ms |
4376 KB |
Output is correct |
14 |
Correct |
16 ms |
4332 KB |
Output is correct |
15 |
Correct |
19 ms |
4736 KB |
Output is correct |
16 |
Correct |
18 ms |
4728 KB |
Output is correct |
17 |
Correct |
17 ms |
4664 KB |
Output is correct |
18 |
Correct |
18 ms |
4872 KB |
Output is correct |
19 |
Correct |
17 ms |
4632 KB |
Output is correct |
20 |
Correct |
13 ms |
5016 KB |
Output is correct |
21 |
Correct |
13 ms |
5020 KB |
Output is correct |
22 |
Correct |
20 ms |
5520 KB |
Output is correct |
23 |
Correct |
20 ms |
5564 KB |
Output is correct |
24 |
Correct |
19 ms |
5492 KB |
Output is correct |
25 |
Correct |
20 ms |
5620 KB |
Output is correct |
26 |
Correct |
20 ms |
5672 KB |
Output is correct |
27 |
Correct |
20 ms |
5624 KB |
Output is correct |
28 |
Correct |
20 ms |
5756 KB |
Output is correct |
29 |
Correct |
19 ms |
5240 KB |
Output is correct |
30 |
Correct |
20 ms |
5508 KB |
Output is correct |
31 |
Correct |
2 ms |
1860 KB |
Output is correct |
32 |
Correct |
2 ms |
1924 KB |
Output is correct |
33 |
Correct |
2 ms |
1996 KB |
Output is correct |
34 |
Correct |
2 ms |
1860 KB |
Output is correct |
35 |
Correct |
2 ms |
1808 KB |
Output is correct |
36 |
Correct |
2 ms |
1796 KB |
Output is correct |
37 |
Correct |
2 ms |
1796 KB |
Output is correct |
38 |
Correct |
2 ms |
1796 KB |
Output is correct |
39 |
Correct |
2 ms |
1792 KB |
Output is correct |
40 |
Correct |
2 ms |
1804 KB |
Output is correct |
41 |
Correct |
2 ms |
1804 KB |
Output is correct |
42 |
Correct |
2 ms |
1860 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
1792 KB |
Output is correct |
2 |
Correct |
2 ms |
1796 KB |
Output is correct |
3 |
Correct |
2 ms |
1800 KB |
Output is correct |
4 |
Correct |
4 ms |
2468 KB |
Output is correct |
5 |
Correct |
4 ms |
2476 KB |
Output is correct |
6 |
Correct |
3 ms |
2476 KB |
Output is correct |
7 |
Correct |
3 ms |
2436 KB |
Output is correct |
8 |
Correct |
4 ms |
2488 KB |
Output is correct |
9 |
Correct |
12 ms |
5740 KB |
Output is correct |
10 |
Correct |
13 ms |
5628 KB |
Output is correct |
11 |
Correct |
12 ms |
5688 KB |
Output is correct |
12 |
Correct |
2 ms |
1868 KB |
Output is correct |
13 |
Correct |
2 ms |
1796 KB |
Output is correct |
14 |
Correct |
2 ms |
1860 KB |
Output is correct |
15 |
Correct |
2 ms |
1796 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
27 ms |
5936 KB |
Output is correct |
2 |
Correct |
41 ms |
6316 KB |
Output is correct |
3 |
Correct |
30 ms |
6432 KB |
Output is correct |
4 |
Correct |
17 ms |
4696 KB |
Output is correct |
5 |
Correct |
17 ms |
5524 KB |
Output is correct |
6 |
Correct |
17 ms |
5284 KB |
Output is correct |
7 |
Correct |
20 ms |
5268 KB |
Output is correct |
8 |
Correct |
19 ms |
5112 KB |
Output is correct |
9 |
Correct |
17 ms |
5024 KB |
Output is correct |
10 |
Correct |
145 ms |
7108 KB |
Output is correct |
11 |
Correct |
191 ms |
7120 KB |
Output is correct |
12 |
Correct |
17 ms |
4356 KB |
Output is correct |
13 |
Correct |
14 ms |
4328 KB |
Output is correct |
14 |
Correct |
15 ms |
4380 KB |
Output is correct |
15 |
Correct |
20 ms |
4676 KB |
Output is correct |
16 |
Correct |
20 ms |
4664 KB |
Output is correct |
17 |
Correct |
19 ms |
4716 KB |
Output is correct |
18 |
Correct |
17 ms |
4780 KB |
Output is correct |
19 |
Correct |
17 ms |
4648 KB |
Output is correct |
20 |
Correct |
13 ms |
4976 KB |
Output is correct |
21 |
Correct |
13 ms |
4964 KB |
Output is correct |
22 |
Correct |
19 ms |
5544 KB |
Output is correct |
23 |
Correct |
20 ms |
5596 KB |
Output is correct |
24 |
Correct |
23 ms |
5480 KB |
Output is correct |
25 |
Correct |
20 ms |
5620 KB |
Output is correct |
26 |
Correct |
20 ms |
5548 KB |
Output is correct |
27 |
Correct |
20 ms |
5752 KB |
Output is correct |
28 |
Correct |
20 ms |
5524 KB |
Output is correct |
29 |
Correct |
18 ms |
5264 KB |
Output is correct |
30 |
Correct |
19 ms |
5424 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
28 ms |
6300 KB |
Output is correct |
2 |
Correct |
31 ms |
6328 KB |
Output is correct |
3 |
Correct |
28 ms |
6356 KB |
Output is correct |
4 |
Correct |
17 ms |
4824 KB |
Output is correct |
5 |
Correct |
18 ms |
5544 KB |
Output is correct |
6 |
Correct |
18 ms |
5276 KB |
Output is correct |
7 |
Correct |
19 ms |
5088 KB |
Output is correct |
8 |
Correct |
19 ms |
5360 KB |
Output is correct |
9 |
Correct |
20 ms |
5312 KB |
Output is correct |
10 |
Correct |
138 ms |
7076 KB |
Output is correct |
11 |
Correct |
162 ms |
7132 KB |
Output is correct |
12 |
Correct |
17 ms |
4428 KB |
Output is correct |
13 |
Correct |
15 ms |
4276 KB |
Output is correct |
14 |
Correct |
14 ms |
4336 KB |
Output is correct |
15 |
Correct |
18 ms |
4720 KB |
Output is correct |
16 |
Correct |
18 ms |
4712 KB |
Output is correct |
17 |
Correct |
17 ms |
4724 KB |
Output is correct |
18 |
Correct |
17 ms |
4576 KB |
Output is correct |
19 |
Correct |
17 ms |
4756 KB |
Output is correct |
20 |
Correct |
12 ms |
4976 KB |
Output is correct |
21 |
Correct |
13 ms |
4976 KB |
Output is correct |
22 |
Correct |
24 ms |
5600 KB |
Output is correct |
23 |
Correct |
20 ms |
5544 KB |
Output is correct |
24 |
Correct |
20 ms |
5432 KB |
Output is correct |
25 |
Correct |
23 ms |
5544 KB |
Output is correct |
26 |
Correct |
22 ms |
5464 KB |
Output is correct |
27 |
Correct |
20 ms |
5780 KB |
Output is correct |
28 |
Correct |
20 ms |
5772 KB |
Output is correct |
29 |
Correct |
22 ms |
5404 KB |
Output is correct |
30 |
Correct |
19 ms |
5512 KB |
Output is correct |
31 |
Correct |
2 ms |
1796 KB |
Output is correct |
32 |
Correct |
2 ms |
1804 KB |
Output is correct |
33 |
Correct |
2 ms |
2056 KB |
Output is correct |
34 |
Correct |
2 ms |
1796 KB |
Output is correct |
35 |
Correct |
2 ms |
1796 KB |
Output is correct |
36 |
Correct |
2 ms |
1872 KB |
Output is correct |
37 |
Correct |
2 ms |
1804 KB |
Output is correct |
38 |
Correct |
2 ms |
1796 KB |
Output is correct |
39 |
Correct |
2 ms |
1804 KB |
Output is correct |
40 |
Correct |
2 ms |
1792 KB |
Output is correct |
41 |
Correct |
2 ms |
1804 KB |
Output is correct |
42 |
Correct |
2 ms |
1804 KB |
Output is correct |