#include "Joi.h"
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define INF (2e9)
#define MOD (1000 * 1000 * 1000 + 7)
#define maxn 10111
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
vector<int> adj[maxn], tree[maxn], one, two, v;
int col[maxn], par[maxn], dep[maxn], max_dep, max_ind, cnt;
bool used[maxn];
void DFS(int x){
used[x] = 1;
if(max_dep < dep[x]){
max_dep = dep[x];
max_ind = x;
}
for(int u : adj[x]){
if(!used[u]){
tree[x].pb(u);
dep[u] = dep[x] + 1;
par[u] = x;
DFS(u);
}
}
}
void colorBig(int x, ll num){
int pos = dep[x] % 60;
int val = (num >> pos) & 1;
col[x] = val;
for(int u : tree[x])
colorBig(u, num);
}
void colorSmall(int x){
v.pb(x);
int last = -1;
for(int u : tree[x]){
if(used[u]){
last = u;
continue;
}
if(cnt <= 0)
continue;
cnt--;
colorSmall(u);
}
if(last != -1)
colorSmall(last);
}
void Joi(int N, int M, int A[], int B[], long long X, int T){
memset(col, 0, sizeof(col));
for(int i = 0; i < M; i++){
adj[A[i]].pb(B[i]);
adj[B[i]].pb(A[i]);
}
par[0] = -1;
dep[0] = 0;
max_dep = -1;
DFS(0);
if(max_dep >= 59)
colorBig(0, X);
else{
memset(used, 0, sizeof(used));
int cur = max_ind;
while(cur != -1){
one.pb(cur);
used[cur] = 1;
cur = par[cur];
}
cnt = 60 - one.size();
colorSmall(0);
sort(v.begin(), v.end());
for(int i = 0; i < v.size(); i++)
col[v[i]] = (X >> i) & 1;
}
for(int i = 0; i < N; i++)
MessageBoard(i, col[i]);
}
#include "Ioi.h"
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define INF (2e9)
#define MOD (1000 * 1000 * 1000 + 7)
#define maxn 10011
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
vector<int> adj1[maxn], tree1[maxn], one1, two1, v1;
int col1[maxn], par1[maxn], dep1[maxn], max_dep1, max_ind1, cnt1;
bool used1[maxn];
void DFS1(int x){
used1[x] = 1;
if(max_dep1 < dep1[x]){
max_dep1 = dep1[x];
max_ind1 = x;
}
for(int u : adj1[x]){
if(!used1[u]){
tree1[x].pb(u);
dep1[u] = dep1[x] + 1;
par1[u] = x;
DFS1(u);
}
}
}
void getSmall(int x){
v1.pb(x);
int last = -1;
for(int u : tree1[x]){
if(used1[u]){
last = u;
continue;
}
if(cnt1 <= 0)
continue;
cnt1--;
col1[u] = Move(u);
getSmall(u);
col1[x] = Move(x);
}
if(last != -1){
col1[last] = Move(last);
getSmall(last);
}
}
long long Ioi(int N, int M, int A[], int B[], int P, int V, int T){
ll ans = 0;
memset(col1, 0, sizeof(col1));
for(int i = 0; i < M; i++){
adj1[A[i]].pb(B[i]);
adj1[B[i]].pb(A[i]);
}
par1[0] = -1;
dep1[0] = 0;
max_dep1 = -1;
DFS1(0);
memset(used1, 0, sizeof(used1));
int cur = max_ind1;
while(cur != -1){
one1.pb(cur);
used1[cur] = 1;
cur = par1[cur];
}
reverse(one1.begin(), one1.end());
if(max_dep1 >= 59){
if(dep1[P] >= 59){ // just go up
int cur = P;
int pos = dep1[cur] % 60;
int val = V;
ans += (1LL << pos) * val;
for(int i = 1; i < 60; i++){
cur = par1[cur];
val = Move(cur);
pos = dep1[cur] % 60;
ans += (1LL << pos) * val;
}
}
else{
cur = par1[P]; // go to 1 and then down
while(cur != -1){
V = Move(cur);
cur = par1[cur];
}
int cur = 0;
int pos = dep1[cur] % 60;
int val = V;
ans += (1LL << pos) * val;
for(int i = 1; i < 60; i++){
cur = one1[i];
val = Move(cur);
pos = dep1[cur] % 60;
ans += (1LL << pos) * val;
}
}
}
else{
int cur = par1[P]; // Move to 1 and then do DFS traversal
while(cur != -1){
V = Move(cur);
cur = par1[cur];
}
cnt1 = 60 - one1.size();
col1[0] = V;
getSmall(0);
sort(v1.begin(), v1.end());
for(int i = 0; i < v1.size(); i++)
ans += col1[v1[i]] * (1LL << i);
}
return ans;
}
Compilation message
Joi.cpp: In function 'void Joi(int, int, int*, int*, long long int, int)':
Joi.cpp:97:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i = 0; i < v.size(); i++)
~~^~~~~~~~~~
Ioi.cpp: In function 'long long int Ioi(int, int, int*, int*, int, int, int)':
Ioi.cpp:134:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i = 0; i < v1.size(); i++)
~~^~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
1784 KB |
Output is correct |
2 |
Correct |
4 ms |
1904 KB |
Output is correct |
3 |
Correct |
4 ms |
1956 KB |
Output is correct |
4 |
Correct |
4 ms |
1852 KB |
Output is correct |
5 |
Correct |
4 ms |
1904 KB |
Output is correct |
6 |
Correct |
4 ms |
2000 KB |
Output is correct |
7 |
Correct |
4 ms |
2004 KB |
Output is correct |
8 |
Correct |
4 ms |
1780 KB |
Output is correct |
9 |
Correct |
4 ms |
1912 KB |
Output is correct |
10 |
Correct |
4 ms |
1916 KB |
Output is correct |
11 |
Correct |
7 ms |
2252 KB |
Output is correct |
12 |
Correct |
4 ms |
1948 KB |
Output is correct |
13 |
Correct |
4 ms |
1784 KB |
Output is correct |
14 |
Correct |
4 ms |
1828 KB |
Output is correct |
15 |
Correct |
4 ms |
1792 KB |
Output is correct |
16 |
Correct |
5 ms |
1912 KB |
Output is correct |
17 |
Correct |
4 ms |
1920 KB |
Output is correct |
18 |
Correct |
4 ms |
1792 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
28 ms |
5572 KB |
Output is correct |
2 |
Correct |
28 ms |
5572 KB |
Output is correct |
3 |
Correct |
27 ms |
5488 KB |
Output is correct |
4 |
Correct |
17 ms |
3640 KB |
Output is correct |
5 |
Correct |
19 ms |
4784 KB |
Output is correct |
6 |
Correct |
18 ms |
4152 KB |
Output is correct |
7 |
Correct |
19 ms |
4380 KB |
Output is correct |
8 |
Correct |
20 ms |
4536 KB |
Output is correct |
9 |
Correct |
19 ms |
4472 KB |
Output is correct |
10 |
Correct |
15 ms |
3640 KB |
Output is correct |
11 |
Correct |
15 ms |
3700 KB |
Output is correct |
12 |
Correct |
15 ms |
3488 KB |
Output is correct |
13 |
Correct |
17 ms |
3624 KB |
Output is correct |
14 |
Correct |
17 ms |
3628 KB |
Output is correct |
15 |
Correct |
18 ms |
3944 KB |
Output is correct |
16 |
Correct |
17 ms |
3888 KB |
Output is correct |
17 |
Correct |
19 ms |
3640 KB |
Output is correct |
18 |
Correct |
18 ms |
3760 KB |
Output is correct |
19 |
Correct |
27 ms |
3660 KB |
Output is correct |
20 |
Correct |
15 ms |
4528 KB |
Output is correct |
21 |
Correct |
15 ms |
4408 KB |
Output is correct |
22 |
Correct |
18 ms |
4152 KB |
Output is correct |
23 |
Correct |
18 ms |
4512 KB |
Output is correct |
24 |
Correct |
17 ms |
4152 KB |
Output is correct |
25 |
Correct |
17 ms |
4280 KB |
Output is correct |
26 |
Correct |
18 ms |
4272 KB |
Output is correct |
27 |
Correct |
18 ms |
4300 KB |
Output is correct |
28 |
Correct |
18 ms |
4536 KB |
Output is correct |
29 |
Correct |
17 ms |
4024 KB |
Output is correct |
30 |
Correct |
18 ms |
4144 KB |
Output is correct |
31 |
Correct |
4 ms |
1904 KB |
Output is correct |
32 |
Correct |
4 ms |
1848 KB |
Output is correct |
33 |
Correct |
4 ms |
1916 KB |
Output is correct |
34 |
Correct |
4 ms |
1912 KB |
Output is correct |
35 |
Correct |
4 ms |
1904 KB |
Output is correct |
36 |
Correct |
4 ms |
1904 KB |
Output is correct |
37 |
Correct |
4 ms |
1908 KB |
Output is correct |
38 |
Correct |
4 ms |
1904 KB |
Output is correct |
39 |
Correct |
4 ms |
1776 KB |
Output is correct |
40 |
Correct |
4 ms |
1912 KB |
Output is correct |
41 |
Correct |
4 ms |
1904 KB |
Output is correct |
42 |
Correct |
4 ms |
1912 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
1780 KB |
Output is correct |
2 |
Correct |
4 ms |
1856 KB |
Output is correct |
3 |
Correct |
4 ms |
1908 KB |
Output is correct |
4 |
Correct |
6 ms |
2444 KB |
Output is correct |
5 |
Correct |
6 ms |
2452 KB |
Output is correct |
6 |
Correct |
7 ms |
2444 KB |
Output is correct |
7 |
Correct |
6 ms |
2452 KB |
Output is correct |
8 |
Correct |
6 ms |
2316 KB |
Output is correct |
9 |
Correct |
16 ms |
5560 KB |
Output is correct |
10 |
Correct |
16 ms |
5816 KB |
Output is correct |
11 |
Correct |
16 ms |
5576 KB |
Output is correct |
12 |
Correct |
4 ms |
1912 KB |
Output is correct |
13 |
Correct |
4 ms |
1912 KB |
Output is correct |
14 |
Correct |
4 ms |
1776 KB |
Output is correct |
15 |
Correct |
4 ms |
1904 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
30 ms |
5452 KB |
Output is correct |
2 |
Correct |
30 ms |
5500 KB |
Output is correct |
3 |
Correct |
30 ms |
5452 KB |
Output is correct |
4 |
Correct |
19 ms |
3664 KB |
Output is correct |
5 |
Correct |
19 ms |
5040 KB |
Output is correct |
6 |
Correct |
19 ms |
4452 KB |
Output is correct |
7 |
Correct |
19 ms |
4492 KB |
Output is correct |
8 |
Correct |
19 ms |
4256 KB |
Output is correct |
9 |
Correct |
19 ms |
4152 KB |
Output is correct |
10 |
Correct |
16 ms |
3636 KB |
Output is correct |
11 |
Correct |
16 ms |
3760 KB |
Output is correct |
12 |
Correct |
16 ms |
3608 KB |
Output is correct |
13 |
Correct |
16 ms |
3568 KB |
Output is correct |
14 |
Correct |
17 ms |
3612 KB |
Output is correct |
15 |
Correct |
18 ms |
3916 KB |
Output is correct |
16 |
Correct |
18 ms |
3896 KB |
Output is correct |
17 |
Correct |
19 ms |
3680 KB |
Output is correct |
18 |
Correct |
18 ms |
3772 KB |
Output is correct |
19 |
Correct |
18 ms |
3748 KB |
Output is correct |
20 |
Correct |
15 ms |
4552 KB |
Output is correct |
21 |
Correct |
15 ms |
4624 KB |
Output is correct |
22 |
Correct |
19 ms |
4152 KB |
Output is correct |
23 |
Correct |
19 ms |
4140 KB |
Output is correct |
24 |
Correct |
19 ms |
4144 KB |
Output is correct |
25 |
Correct |
18 ms |
4372 KB |
Output is correct |
26 |
Correct |
17 ms |
4288 KB |
Output is correct |
27 |
Correct |
17 ms |
4400 KB |
Output is correct |
28 |
Correct |
22 ms |
4232 KB |
Output is correct |
29 |
Correct |
17 ms |
4260 KB |
Output is correct |
30 |
Correct |
17 ms |
4208 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
27 ms |
5448 KB |
Output is correct |
2 |
Correct |
28 ms |
5536 KB |
Output is correct |
3 |
Correct |
27 ms |
5444 KB |
Output is correct |
4 |
Correct |
17 ms |
3784 KB |
Output is correct |
5 |
Correct |
19 ms |
5168 KB |
Output is correct |
6 |
Correct |
19 ms |
4176 KB |
Output is correct |
7 |
Correct |
19 ms |
4216 KB |
Output is correct |
8 |
Correct |
19 ms |
4412 KB |
Output is correct |
9 |
Correct |
19 ms |
4524 KB |
Output is correct |
10 |
Correct |
17 ms |
3644 KB |
Output is correct |
11 |
Correct |
17 ms |
3760 KB |
Output is correct |
12 |
Correct |
17 ms |
3608 KB |
Output is correct |
13 |
Correct |
17 ms |
3624 KB |
Output is correct |
14 |
Correct |
18 ms |
3556 KB |
Output is correct |
15 |
Correct |
19 ms |
3984 KB |
Output is correct |
16 |
Correct |
19 ms |
4164 KB |
Output is correct |
17 |
Correct |
19 ms |
3640 KB |
Output is correct |
18 |
Correct |
19 ms |
3644 KB |
Output is correct |
19 |
Correct |
17 ms |
3760 KB |
Output is correct |
20 |
Correct |
15 ms |
4528 KB |
Output is correct |
21 |
Correct |
15 ms |
4592 KB |
Output is correct |
22 |
Correct |
19 ms |
4432 KB |
Output is correct |
23 |
Correct |
19 ms |
4176 KB |
Output is correct |
24 |
Correct |
19 ms |
4152 KB |
Output is correct |
25 |
Correct |
19 ms |
4152 KB |
Output is correct |
26 |
Correct |
19 ms |
3888 KB |
Output is correct |
27 |
Correct |
19 ms |
4428 KB |
Output is correct |
28 |
Correct |
19 ms |
4532 KB |
Output is correct |
29 |
Correct |
18 ms |
4304 KB |
Output is correct |
30 |
Correct |
18 ms |
4264 KB |
Output is correct |
31 |
Correct |
4 ms |
1916 KB |
Output is correct |
32 |
Correct |
4 ms |
1980 KB |
Output is correct |
33 |
Correct |
4 ms |
1992 KB |
Output is correct |
34 |
Correct |
4 ms |
1972 KB |
Output is correct |
35 |
Correct |
4 ms |
1776 KB |
Output is correct |
36 |
Correct |
4 ms |
1940 KB |
Output is correct |
37 |
Correct |
4 ms |
1776 KB |
Output is correct |
38 |
Correct |
4 ms |
2016 KB |
Output is correct |
39 |
Correct |
4 ms |
1784 KB |
Output is correct |
40 |
Correct |
4 ms |
1844 KB |
Output is correct |
41 |
Correct |
4 ms |
2004 KB |
Output is correct |
42 |
Correct |
4 ms |
1904 KB |
Output is correct |