#include<bits/stdc++.h>
#include "Joi.h"
using namespace std;
#define all(fl) fl.begin(),fl.end()
#define pb push_back
#define fi first
#define se second
#define for1(i,j,k) for(int i=j;i<=k;i++)
#define for2(i,j,k) for(int i=j;i>=k;i--)
#define for3(i,j,k,l) for(int i=j;i<=k;i+=l)
#define lb lower_bound
#define ub upper_bound
#define sz(a) (int)a.size()
#define pii pair<int,int>
#define pli pair<long long,int>
#define gcd __gcd
#define lcm(x,y) x*y/__gcd(x,y)
const int maxn=1e4+9;
vector<int>a[maxn];
vector<int>g[maxn];
bool vis[maxn];
void predfs(int u){
vis[u]=1;
for (auto v:a[u]){
if (!vis[v]){
g[u].pb(v);
g[v].pb(u);
predfs(v);
}
}
}
int d[maxn],sub[maxn],p[maxn];
void dfs(int u,int par){
sub[u]=d[u];
for (auto v:g[u]){
if (v==par)continue;
d[v]=d[u]+1;
p[v]=u;
dfs(v,u);
sub[u]=max(sub[u],sub[v]);
}
}
int in[maxn],tme=0;
bool vcl[maxn];
void solve(int u,int par){
in[u]=tme++;
sort(all(a[u]),[](int i,int j){
return vcl[i]<vcl[j];
});
for (auto v:a[u]){
if (v==par)continue;
solve(v,u);
}
}
void add(int u,int v){
a[u].pb(v);
a[v].pb(u);
}
void Joi(int N, int M, int A[], int B[], long long X, int T) {
for1(i,0,M-1){
a[A[i]].pb(B[i]);
a[B[i]].pb(A[i]);
}
for1(i,0,N-1)sort(all(a[i]));
tme=0;
for1(i,0,N-1){
vcl[i]=in[i]=d[i]=sub[i]=vis[i]=0;
}
predfs(0);
dfs(0,0);
if (sub[0]+1>=60){
for1(i,0,N-1){
long long bit=d[i]%60;
MessageBoard(i,(X>>bit&1ll));
}
return;
}
for1(i,0,N-1)a[i].clear();
int nw=0;
for1(i,0,N-1)if (d[i]>d[nw])nw=i;
for1(i,0,N-1)vis[i]=0;
queue<int>t;
t.push(0);
vis[0]=1;
int tmp=nw;
int cnt=1;
while (tmp!=0){
add(p[tmp],tmp);
vcl[tmp]=vcl[p[tmp]]=1;
vis[tmp]=1;
cnt++;
t.push(tmp);
tmp=p[tmp];
}
while (!t.empty()){
auto u=t.front();
t.pop();
for (auto v:g[u]){
if (vis[v])continue;
if (cnt==60)break;
add(u,v);
vis[v]=1;
t.push(v);
cnt++;
}
}
solve(0,0);
int dem=0;
for1(i,0,N-1){
if (!vis[i]){
MessageBoard(i,0);
}
else {
long long bit=in[i]%60;
MessageBoard(i,(X>>bit&1ll));
}
}
}
#include<bits/stdc++.h>
#include "Ioi.h"
using namespace std;
#define all(fl) fl.begin(),fl.end()
#define pb push_back
#define fi first
#define se second
#define for1(i,j,k) for(int i=j;i<=k;i++)
#define for2(i,j,k) for(int i=j;i>=k;i--)
#define for3(i,j,k,l) for(int i=j;i<=k;i+=l)
#define lb lower_bound
#define ub upper_bound
#define sz(a) (int)a.size()
#define pii pair<int,int>
#define pli pair<long long,int>
#define gcd __gcd
#define lcm(x,y) x*y/__gcd(x,y)
const int maxn=1e4+9;
vector<int>a[maxn];
vector<int>g[maxn];
bool vis[maxn];
void predfs(int u){
vis[u]=1;
for (auto v:a[u]){
if (!vis[v]){
g[u].pb(v);
g[v].pb(u);
predfs(v);
}
}
}
int d[maxn],sub[maxn],p[maxn];
void dfs(int u,int par){
sub[u]=d[u];
for (auto v:g[u]){
if (v==par)continue;
d[v]=d[u]+1;
p[v]=u;
dfs(v,u);
sub[u]=max(sub[u],sub[v]);
}
}
int in[maxn],tme=0;
bool vcl[maxn];
void solve(int u,int par){
in[u]=tme++;
sort(all(a[u]),[](int i,int j){
return vcl[i]<vcl[j];
});
for (auto v:a[u]){
if (v==par)continue;
solve(v,u);
}
}
void add(int u,int v){
a[u].pb(v);
a[v].pb(u);
}
bool type[maxn];
bool need[maxn];
int step=0;
void dfs1(int u,int par){
step++;
if (step==60)return;
sort(all(g[u]),[](int i,int j){
return sub[i]>sub[j];
});
for (auto v:g[u]){
if (v==par)continue;
need[v]=1;
type[v]=Move(v);
dfs1(v,u);
break;
}
}
bool fl=false;
void last(int u,int par,int vertice){
if (u==vertice)fl=true;
need[u]=1;
for (auto v:a[u]){
if (v==par)continue;
type[v]=Move(v);
last(v,u,vertice);
if (!fl){
type[u]=Move(u);
}
}
}
long long Ioi(int N, int M, int A[], int B[], int P, int V, int T) {
for1(i,0,N-1){
a[i].clear(),g[i].clear();
}
for1(i,0,M-1){
a[A[i]].pb(B[i]);
a[B[i]].pb(A[i]);
}
for1(i,0,N-1)sort(all(a[i]));
tme=0;
for1(i,0,N-1){
vcl[i]=in[i]=d[i]=sub[i]=vis[i]=0;
}
predfs(0);
dfs(0,0);
if (sub[0]+1>=60){
int u=P;
while (sub[u]-d[u]+1<60){
type[p[u]]=Move(p[u]);
u=p[u];
}
need[u]=1;
type[P]=V;
dfs1(u,p[u]);
long long ans=0;
for1(i,0,N-1){
if (need[i]&&type[i]){
long long bit=d[i]%60;
ans+=(1ll<<bit);
}
}
return ans;
}
for1(i,0,N-1)a[i].clear();
int nw=0;
for1(i,0,N-1)if (d[i]>d[nw])nw=i;
for1(i,0,N-1)vis[i]=0;
queue<int>t;
t.push(0);
vis[0]=1;
int tmp=nw;
int cnt=1;
while (tmp!=0){
add(p[tmp],tmp);
vcl[tmp]=vcl[p[tmp]]=1;
vis[tmp]=1;
cnt++;
t.push(tmp);
tmp=p[tmp];
}
while (!t.empty()){
auto u=t.front();
t.pop();
for (auto v:g[u]){
if (vis[v])continue;
if (cnt==60)break;
add(u,v);
vis[v]=1;
t.push(v);
cnt++;
}
}
solve(0,0);
int u=P;
while (u!=0){
type[p[u]]=Move(p[u]);
u=p[u];
}
need[0]=1;
last(0,0,nw);
long long ans=0;
for1(i,0,N-1){
if (need[i]&&type[i]){
long long bit=in[i]%60;
ans+=(1ll<<bit);
}
}
return ans;
}
Compilation message
Joi.cpp: In function 'void Joi(int, int, int*, int*, long long int, int)':
Joi.cpp:67:13: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
67 | vcl[i]=in[i]=d[i]=sub[i]=vis[i]=0;
| ~~~~~^~~~~~~~~~~~~~~~~~~~~
Joi.cpp:108:5: warning: unused variable 'dem' [-Wunused-variable]
108 | int dem=0;
| ^~~
Ioi.cpp: In function 'long long int Ioi(int, int, int*, int*, int, int, int)':
Ioi.cpp:100:13: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
100 | vcl[i]=in[i]=d[i]=sub[i]=vis[i]=0;
| ~~~~~^~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1820 KB |
Output is correct |
2 |
Correct |
2 ms |
1808 KB |
Output is correct |
3 |
Correct |
2 ms |
1824 KB |
Output is correct |
4 |
Correct |
1 ms |
1820 KB |
Output is correct |
5 |
Correct |
2 ms |
1820 KB |
Output is correct |
6 |
Correct |
1 ms |
1820 KB |
Output is correct |
7 |
Correct |
2 ms |
1816 KB |
Output is correct |
8 |
Correct |
2 ms |
1824 KB |
Output is correct |
9 |
Correct |
2 ms |
1828 KB |
Output is correct |
10 |
Correct |
1 ms |
1820 KB |
Output is correct |
11 |
Correct |
4 ms |
2124 KB |
Output is correct |
12 |
Correct |
1 ms |
1808 KB |
Output is correct |
13 |
Correct |
2 ms |
1808 KB |
Output is correct |
14 |
Correct |
1 ms |
1808 KB |
Output is correct |
15 |
Correct |
2 ms |
1812 KB |
Output is correct |
16 |
Correct |
2 ms |
1808 KB |
Output is correct |
17 |
Correct |
2 ms |
1816 KB |
Output is correct |
18 |
Correct |
1 ms |
1816 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
19 ms |
5716 KB |
Output is correct |
2 |
Correct |
20 ms |
5736 KB |
Output is correct |
3 |
Correct |
20 ms |
5740 KB |
Output is correct |
4 |
Correct |
13 ms |
4064 KB |
Output is correct |
5 |
Correct |
12 ms |
4828 KB |
Output is correct |
6 |
Correct |
13 ms |
4568 KB |
Output is correct |
7 |
Correct |
12 ms |
4568 KB |
Output is correct |
8 |
Correct |
15 ms |
4816 KB |
Output is correct |
9 |
Correct |
12 ms |
4840 KB |
Output is correct |
10 |
Correct |
11 ms |
4312 KB |
Output is correct |
11 |
Correct |
15 ms |
4284 KB |
Output is correct |
12 |
Correct |
11 ms |
3788 KB |
Output is correct |
13 |
Correct |
12 ms |
3868 KB |
Output is correct |
14 |
Correct |
11 ms |
4052 KB |
Output is correct |
15 |
Correct |
12 ms |
4068 KB |
Output is correct |
16 |
Correct |
12 ms |
4064 KB |
Output is correct |
17 |
Correct |
12 ms |
4056 KB |
Output is correct |
18 |
Correct |
12 ms |
4052 KB |
Output is correct |
19 |
Correct |
12 ms |
4320 KB |
Output is correct |
20 |
Correct |
9 ms |
4832 KB |
Output is correct |
21 |
Correct |
10 ms |
4932 KB |
Output is correct |
22 |
Correct |
12 ms |
4308 KB |
Output is correct |
23 |
Correct |
12 ms |
4828 KB |
Output is correct |
24 |
Correct |
12 ms |
4576 KB |
Output is correct |
25 |
Correct |
12 ms |
4580 KB |
Output is correct |
26 |
Correct |
12 ms |
4836 KB |
Output is correct |
27 |
Correct |
12 ms |
4840 KB |
Output is correct |
28 |
Correct |
13 ms |
4832 KB |
Output is correct |
29 |
Correct |
11 ms |
4500 KB |
Output is correct |
30 |
Correct |
11 ms |
4568 KB |
Output is correct |
31 |
Correct |
2 ms |
1816 KB |
Output is correct |
32 |
Correct |
2 ms |
1808 KB |
Output is correct |
33 |
Correct |
1 ms |
2020 KB |
Output is correct |
34 |
Correct |
1 ms |
1820 KB |
Output is correct |
35 |
Correct |
1 ms |
1820 KB |
Output is correct |
36 |
Correct |
1 ms |
1820 KB |
Output is correct |
37 |
Correct |
1 ms |
1808 KB |
Output is correct |
38 |
Correct |
2 ms |
1808 KB |
Output is correct |
39 |
Correct |
1 ms |
1820 KB |
Output is correct |
40 |
Correct |
1 ms |
1808 KB |
Output is correct |
41 |
Correct |
1 ms |
1804 KB |
Output is correct |
42 |
Correct |
0 ms |
1816 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1820 KB |
Output is correct |
2 |
Correct |
1 ms |
1812 KB |
Output is correct |
3 |
Correct |
1 ms |
1824 KB |
Output is correct |
4 |
Correct |
3 ms |
2828 KB |
Output is correct |
5 |
Correct |
4 ms |
2368 KB |
Output is correct |
6 |
Correct |
3 ms |
2368 KB |
Output is correct |
7 |
Correct |
2 ms |
2368 KB |
Output is correct |
8 |
Correct |
3 ms |
2368 KB |
Output is correct |
9 |
Correct |
10 ms |
5956 KB |
Output is correct |
10 |
Correct |
10 ms |
5952 KB |
Output is correct |
11 |
Correct |
10 ms |
6196 KB |
Output is correct |
12 |
Correct |
1 ms |
1824 KB |
Output is correct |
13 |
Correct |
2 ms |
1824 KB |
Output is correct |
14 |
Correct |
2 ms |
1820 KB |
Output is correct |
15 |
Correct |
1 ms |
1808 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
19 ms |
5732 KB |
Output is correct |
2 |
Correct |
19 ms |
5724 KB |
Output is correct |
3 |
Correct |
19 ms |
5732 KB |
Output is correct |
4 |
Correct |
15 ms |
4064 KB |
Output is correct |
5 |
Correct |
12 ms |
5336 KB |
Output is correct |
6 |
Correct |
12 ms |
4828 KB |
Output is correct |
7 |
Correct |
12 ms |
4824 KB |
Output is correct |
8 |
Correct |
12 ms |
4408 KB |
Output is correct |
9 |
Correct |
12 ms |
4916 KB |
Output is correct |
10 |
Correct |
12 ms |
4424 KB |
Output is correct |
11 |
Correct |
11 ms |
4412 KB |
Output is correct |
12 |
Correct |
11 ms |
3880 KB |
Output is correct |
13 |
Correct |
11 ms |
3936 KB |
Output is correct |
14 |
Correct |
11 ms |
4404 KB |
Output is correct |
15 |
Correct |
12 ms |
4412 KB |
Output is correct |
16 |
Correct |
12 ms |
4420 KB |
Output is correct |
17 |
Correct |
12 ms |
4372 KB |
Output is correct |
18 |
Correct |
12 ms |
4412 KB |
Output is correct |
19 |
Correct |
13 ms |
4412 KB |
Output is correct |
20 |
Correct |
10 ms |
4896 KB |
Output is correct |
21 |
Correct |
10 ms |
5184 KB |
Output is correct |
22 |
Correct |
13 ms |
4920 KB |
Output is correct |
23 |
Correct |
14 ms |
4920 KB |
Output is correct |
24 |
Correct |
13 ms |
4920 KB |
Output is correct |
25 |
Correct |
12 ms |
4924 KB |
Output is correct |
26 |
Correct |
12 ms |
4920 KB |
Output is correct |
27 |
Correct |
12 ms |
4912 KB |
Output is correct |
28 |
Correct |
12 ms |
4928 KB |
Output is correct |
29 |
Correct |
11 ms |
4372 KB |
Output is correct |
30 |
Correct |
12 ms |
4908 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
22 ms |
5732 KB |
Output is correct |
2 |
Correct |
20 ms |
5728 KB |
Output is correct |
3 |
Correct |
19 ms |
5728 KB |
Output is correct |
4 |
Correct |
12 ms |
4060 KB |
Output is correct |
5 |
Correct |
12 ms |
5432 KB |
Output is correct |
6 |
Correct |
12 ms |
4564 KB |
Output is correct |
7 |
Correct |
12 ms |
4924 KB |
Output is correct |
8 |
Correct |
12 ms |
4924 KB |
Output is correct |
9 |
Correct |
13 ms |
4912 KB |
Output is correct |
10 |
Correct |
11 ms |
4336 KB |
Output is correct |
11 |
Correct |
14 ms |
4312 KB |
Output is correct |
12 |
Correct |
10 ms |
3872 KB |
Output is correct |
13 |
Correct |
11 ms |
3880 KB |
Output is correct |
14 |
Correct |
12 ms |
4400 KB |
Output is correct |
15 |
Correct |
12 ms |
4420 KB |
Output is correct |
16 |
Correct |
12 ms |
4416 KB |
Output is correct |
17 |
Correct |
12 ms |
4420 KB |
Output is correct |
18 |
Correct |
12 ms |
4404 KB |
Output is correct |
19 |
Correct |
12 ms |
4416 KB |
Output is correct |
20 |
Correct |
10 ms |
4924 KB |
Output is correct |
21 |
Correct |
10 ms |
4932 KB |
Output is correct |
22 |
Correct |
12 ms |
4920 KB |
Output is correct |
23 |
Correct |
13 ms |
4896 KB |
Output is correct |
24 |
Correct |
12 ms |
4928 KB |
Output is correct |
25 |
Correct |
12 ms |
4932 KB |
Output is correct |
26 |
Correct |
12 ms |
4664 KB |
Output is correct |
27 |
Correct |
16 ms |
4932 KB |
Output is correct |
28 |
Correct |
16 ms |
4928 KB |
Output is correct |
29 |
Correct |
11 ms |
4896 KB |
Output is correct |
30 |
Correct |
12 ms |
4912 KB |
Output is correct |
31 |
Correct |
1 ms |
1824 KB |
Output is correct |
32 |
Correct |
2 ms |
1812 KB |
Output is correct |
33 |
Correct |
1 ms |
1820 KB |
Output is correct |
34 |
Correct |
1 ms |
2064 KB |
Output is correct |
35 |
Correct |
1 ms |
1820 KB |
Output is correct |
36 |
Correct |
1 ms |
1812 KB |
Output is correct |
37 |
Correct |
1 ms |
1816 KB |
Output is correct |
38 |
Correct |
1 ms |
1824 KB |
Output is correct |
39 |
Correct |
1 ms |
1812 KB |
Output is correct |
40 |
Correct |
1 ms |
1824 KB |
Output is correct |
41 |
Correct |
1 ms |
1824 KB |
Output is correct |
42 |
Correct |
1 ms |
1808 KB |
Output is correct |