This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "Joi.h"
#include <bits/stdc++.h>
#pragma optimize("Ofast")
#pragma target("avx2")
using namespace std;
#define ll long long
#define ld long double
#define pb push_back
#define pf push_front
#define pii pair<int,int>
#define all(v) v.begin(),v.end()
#define F first
#define S second
#define mem(a,i) memset(a,i,sizeof(a))
#define sz(s) (int)s.size()
#define y1 yy
#define ppb pop_back
#define lb lower_bound
#define ub upper_bound
#define gcd(a,b) __gcd(a,b)
#define in insert
// #define int ll
const int MAX=1e5+15;
const int B=500;
const int maxB=1000;
const int N=104;
const int block=450;
const ll inf=1e9;
const int mod=1e9+7;
const int mod1=1e9+9;
const ld eps=1e-9;
int dx[8]={1,0,-1,0,1,-1,-1,1};
int dy[8]={0,1,0,-1,1,-1,1,-1};
int binpow(int a,int n){
if(!n)return 1;
if(n%2==1)return a*binpow(a,n-1)%mod;
int k=binpow(a,n/2);
return k*k%mod;
}
struct JOIKUN{
vector<int> g[MAX];
vector<int> g1[MAX];
int use[MAX];
int d[MAX],root;
void dfs(int v){
use[v]=1;
for(auto to:g[v]){
if(!use[to]){
d[to]=d[v]+1;
g1[v].pb(to);
g1[to].pb(v);
dfs(to);
}
}
}
int mxD=0;
int D[MAX];
void dfs1(int v,int p=-1){
mxD=max(mxD,d[v]+1);
for(auto to:g1[v]){
if(to==p)continue;
d[to]=d[v]+1;
dfs1(to,v);
}
}
void calc(int v,int p=-1){
D[v]=v;
for(auto to:g1[v]){
if(to==p)continue;
calc(to,v);
if(d[D[v]]<d[D[to]])D[v]=D[to];
}
}
int bit(ll i,int j){
return (i>>j)&1;
}
vector<int> top;
void topsort(int v,int p=-1){
top.pb(v);
for(auto to:g[v]){
if(to==p)continue;
topsort(to,v);
}
}
void solve(int N,int M,int A[],int B[],ll X,int T){
for(int i=0;i<M;i++){
g[A[i]].pb(B[i]);
g[B[i]].pb(A[i]);
}
dfs(0);
for(int i=0;i<N;i++){
use[i]=0;
if(d[i]>d[root])root=i;
}
d[root]=0;
dfs1(root);
calc(root);
if(mxD>=60){
// cout<<X<<"\n";
for(int i=0;i<N;i++){
MessageBoard(i,bit(X,d[i]%60));
}
return;
}
topsort(root);
for(int i=0;i<N;i++){
MessageBoard(top[i],bit(X,i%60));
}
}
}t;
void Joi(int N, int M, int A[], int B[], long long X, int T) {
t.solve(N,M,A,B,X,T);
}
#include "Ioi.h"
#include <bits/stdc++.h>
#pragma optimize("Ofast")
#pragma target("avx2")
using namespace std;
#define ll long long
#define ld long double
#define pb push_back
#define pf push_front
#define pii pair<int,int>
#define all(v) v.begin(),v.end()
#define F first
#define S second
#define mem(a,i) memset(a,i,sizeof(a))
#define sz(s) (int)s.size()
#define y1 yy
#define ppb pop_back
#define lb lower_bound
#define ub upper_bound
#define gcd(a,b) __gcd(a,b)
#define in insert
// #define int ll
const int MAX=1e5+15;
const int B=500;
const int maxB=1000;
const int N=104;
const int block=450;
const ll inf=1e9;
const int mod=1e9+7;
const int mod1=1e9+9;
const ld eps=1e-9;
struct IOICHAN{
ll ans=0;
vector<int> g[MAX];
vector<int> g1[MAX];
int use[MAX];
int d[MAX],root;
int pr[MAX];
void dfs(int v){
use[v]=1;
for(auto to:g[v]){
if(!use[to]){
d[to]=d[v]+1;
g1[v].pb(to);
g1[to].pb(v);
dfs(to);
}
}
}
int mxD=0;
int D[MAX];
int big[MAX];
void dfs1(int v,int p=-1){
pr[v]=p;
mxD=max(mxD,d[v]+1);
for(auto to:g1[v]){
if(to==p)continue;
d[to]=d[v]+1;
dfs1(to,v);
}
}
void calc(int v,int p=-1){
D[v]=v;
big[v]=-1;
for(auto to:g1[v]){
if(to==p)continue;
calc(to,v);
if(d[D[v]]<d[D[to]]){
D[v]=D[to];
big[v]=to;
}
}
}
int bit(ll i,int j){
return (i>>j)&1;
}
vector<int> top;
void topsort(int v,int p=-1){
top.pb(v);
for(auto to:g[v]){
if(to==p)continue;
topsort(to,v);
}
}
set<pii> st;
ll solve(int N,int M,int A[],int B[],int P,int V,int T){
for(int i=0;i<M;i++){
g[A[i]].pb(B[i]);
g[B[i]].pb(A[i]);
st.in({A[i],B[i]});
st.in({B[i],A[i]});
}
dfs(0);
for(int i=0;i<N;i++){
use[i]=0;
if(d[i]>d[root])root=i;
}
d[root]=0;
dfs1(root);
calc(root);
if(mxD+1>=60){
while(d[P]%60!=0&&d[D[P]]-d[P]>=59){
V=Move(pr[P]);
P=pr[P];
}
ans+=V*(1ll<<0);
for(int i=1;i<60;i++){
V=Move(big[P]);
P=big[P];
ans+=V*(1ll<<i);
}
// cout<<ans<<"\n";
return ans;
}
topsort(root);
while(P!=root){
V=Move(pr[P]);
P=pr[P];
}
ans+=V*(1ll<<0);
for(int i=1;i<60;i++){
int L=top[i];
while(P!=L){
if(st.count({P,L})){
V=Move(L);
P=L;
}
else{
V=Move(pr[P]);
P=pr[P];
}
}
ans+=V*(1ll<<i);
}
return ans;
}
}g;
long long Ioi(int N, int M, int A[], int B[], int P, int V, int T) {
return g.solve(N,M,A,B,P,V,T);
}
Compilation message (stderr)
Joi.cpp:5: warning: ignoring '#pragma optimize ' [-Wunknown-pragmas]
5 | #pragma optimize("Ofast")
|
Joi.cpp:6: warning: ignoring '#pragma target ' [-Wunknown-pragmas]
6 | #pragma target("avx2")
|
Ioi.cpp:5: warning: ignoring '#pragma optimize ' [-Wunknown-pragmas]
5 | #pragma optimize("Ofast")
|
Ioi.cpp:6: warning: ignoring '#pragma target ' [-Wunknown-pragmas]
6 | #pragma target("avx2")
|
# | 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... |