#include "Joi.h"
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ld long double
#define show(x,y) cout << y << " " << #x << endl;
#define show2(x,y,i,j) cout << y << " " << #x << " " << j << " " << #i << endl;
#define show3(x,y,i,j,p,q) cout << y << " " << #x << " " << j << " " << #i << " " << q << " " << #p << endl;
#define show4(x,y) for(auto it:y) cout << it << " "; cout << #x << endl;
typedef pair<int,int>pii;
mt19937_64 rng(chrono::system_clock::now().time_since_epoch().count());
//MessageBoard(index,val)
struct DSU{
vector<int>e;
void init(int n){
e=vector<int>(n,-1);
}
int get(int x){
return e[x]<0?x:e[x]=get(e[x]);
}
bool unite(int x, int y){
x=get(x); y=get(y);
if(x==y) return 0;
if(e[x]>e[y]) swap(x,y);
e[x]+=e[y];
e[y]=x;
return 1;
}
};
vector<int>adj[10005];
int in[10005];
int ptr=-1;
vector<int>storage[65];
void dfs(int index, int par){
in[index]=++ptr;
storage[in[index]%60].push_back(index);
for(auto it:adj[index]){
if(it==par) continue;
dfs(it,index);
}
}
void Joi(int32_t n, int32_t m, int32_t a[], int32_t b[], long long val, int32_t t){
DSU dsu;
dsu.init(n+5);
for(int x=0;x<m;x++){
if(dsu.unite(a[x],b[x])){
adj[a[x]].push_back(b[x]);
adj[b[x]].push_back(a[x]);
}
}
dfs(0,-1);
for(int x=0;x<60;x++){
if(val&(1LL<<x)){
for(auto it:storage[x]){
MessageBoard(it,1);
}
}
else{
for(auto it:storage[x]){
MessageBoard(it,0);
}
}
}
}
#include "Ioi.h"
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ld long double
#define show(x,y) cout << y << " " << #x << endl;
#define show2(x,y,i,j) cout << y << " " << #x << " " << j << " " << #i << endl;
#define show3(x,y,i,j,p,q) cout << y << " " << #x << " " << j << " " << #i << " " << q << " " << #p << endl;
#define show4(x,y) for(auto it:y) cout << it << " "; cout << #x << endl;
typedef pair<int,int>pii;
mt19937_64 rng(chrono::system_clock::now().time_since_epoch().count());
//MessageBoard(index,val)
struct DSU{
vector<int>e;
void init(int n){
e=vector<int>(n,-1);
}
int get(int x){
return e[x]<0?x:e[x]=get(e[x]);
}
bool unite(int x, int y){
x=get(x); y=get(y);
if(x==y) return 0;
if(e[x]>e[y]) swap(x,y);
e[x]+=e[y];
e[y]=x;
return 1;
}
};
vector<int>adj[10005];
int in[10005];
int ptr=-1;
int pp[10005];
void dfs(int index, int par){
in[index]=++ptr;
for(auto it:adj[index]){
if(it==par) continue;
dfs(it,index);
pp[it]=index;
}
}
int ans[60];
int cnt=0;
void f(int index){
if(cnt>200) return;
//~ cnt++;
int hold=Move(index);
ans[in[index]%60]=hold;
}
bool visited[10005];
void dfs2(int index, int par){
visited[index]=true;
for(auto it:adj[index]){
if(it==par) continue;
if(visited[it]) continue;
f(it);
dfs2(it,index);
}
if(par!=-1)f(par);
}
long long Ioi(int32_t n, int32_t m, int32_t a[], int32_t b[], int32_t p, int32_t v, int32_t t){
DSU dsu;
dsu.init(n+5);
for(int x=0;x<m;x++){
if(dsu.unite(a[x],b[x])){
adj[a[x]].push_back(b[x]);
adj[b[x]].push_back(a[x]);
}
}
memset(pp,-1,sizeof(pp));
dfs(0,-1);
memset(ans,-1,sizeof(ans));
ans[in[p]%60]=v;
dfs2(p,pp[p]);
int take=0;
for(int x=0;x<60;x++){
take+=(1LL<<x)*ans[x];
}
return take;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |