답안 #112835

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
112835 2019-05-22T06:39:14 Z ckodser Amusement Park (JOI17_amusement_park) C++14
컴파일 오류
0 ms 0 KB
#include<bits/stdc++.h>
#include<Joi.h>


#define ll long long
#define pb push_back
#define mp make_pair
#define ld long double
#define F first
#define S second
#define pii pair<ll,ll> 

using namespace :: std;

const ll mod=1e9+7;
const ll maxn=1e5+500;
const ll inf=1e9+900;

vector<ll> ger[maxn];
vector<ll> tree[maxn];

bool vis[maxn];
bool ans[maxn];
bool in_path[maxn];
ll h[maxn];
vector<ll> tartib;
vector<ll> dfss;
ll newras;

void clearr(){
    memset(ans,0,sizeof ans);
    memset(h,0,sizeof h);
    memset(in_path,0,sizeof in_path);
    memset(chand,0,sizeof chand);

    tartib.clear();
    dfss.clear();
    for(ll i=0;i<maxn;i++){
	ger[i].clear();
	tree[i].clear();
    }
}
pii find_far(ll v){
    vis[v]=1;
    pii ans=mp(0,v);
    for(auto u:ger[v]){
	if(!vis[u]){
	    pii e=find_far(u);
	    e.F++;
	    ans=max(ans,e);
	}
    }
    return ans;
}
pair<pii,ll> find_rot(ll n,ll m){
    pii e=find_far(0);
    memset(vis,0,sizeof vis);
    pii r=find_far(e.S);
    memset(vis,0,sizeof vis);
    return mp(mp(r.S,e.S),r.F); 
}
bool  dfs(ll a,ll b){
    bool ans=0;
    if(a==b)ans=1;
    vis[a]=1;
    for(auto v:ger[a]){
	if(!vis[v]){
	    tree[a].pb(v);
	    ans|=dfs(v,b);
	}
    }
    in_path[a]=ans;
    return ans;
}
void dfs_2(ll a){
    tartib.pb(a);
    dfss.pb(a);
    if(!in_path[a])newras--;
    for(auto v:tree[a]){
	if(newras && in_path[v]==0){
	    dfs_2(v);
	    dfss.pb(a);
	}
    }
    for(auto v:tree[a]){
	if(in_path[v]){
	    dfs_2(v);
	}
    }
}
void make_tartib(pair<pii,ll> e){
    ll a=e.F.F;
    ll b=e.F.S;
    memset(vis,0,sizeof vis);
    dfs(a,b);
    newras=60-(e.S+1);
    dfs_2(a);
}
void bfs(ll a){
    memset(vis,0,sizeof vis);
    memset(h,0,sizeof h);
    queue<ll> qu;
    qu.push(a);
    vis[a]=1;
    h[a]=0;
    while(qu.size()){
	ll v=qu.front();
	qu.pop();
	ans[v]=((x>>(h[v]%60))&1);
	for(auto u:ger[v]){
	    if(!vis[u]){
		qu.push(u);
		vis[u]=1;
		h[u]=h[v]+1;
	    }
	}
    }
}
void Joi(int n, int m, int A[], int B[], long long X, int T){
    clearr();    
    for(ll i=0;i<m;i++){
	ger[A[i]].pb(B[i]);
	ger[B[i]].pb(A[i]);
    }
    pair<pii,ll> ew=find_rot(n,m);
    pii r=mp(ew.S,ew.F.F);
    if(r.F>=60){
	bfs(r.S);
	for(ll i=0;i<n;i++){
	    MessageBoard(i,ans[i]);
	}
	return ;
    }else{
	make_tartib(ew);
	set<ll> st;
	for(ll i=0;i<n;i++){
	    st.insert(i);
	}
	for(ll i=0;i<tartib.size();i++){
	    MessageBoard(tartib[i],(x>>i)&1);
	    st.erase(tartib[i]);
	}
	for(auto v:st){
	    MessageBoard(v,0);
	}
	return;
    }
}
#include<bits/stdc++.h>
#include<Ioi.h>


#define ll long long
#define pb push_back
#define mp make_pair
#define ld long double
#define F first
#define S second
#define pii pair<ll,ll> 

using namespace :: std;

const ll mod=1e9+7;
const ll maxn=1e5+500;
const ll inf=1e9+900;


vector<ll> ger[maxn];
vector<ll> tree[maxn];

bool vis[maxn];
bool ans[maxn];
bool in_path[maxn];
ll h[maxn];
vector<ll> tartib;
vector<ll> dfss;
ll chand[maxn];
ll newras;

void clearr(){
    memset(ans,0,sizeof ans);
    memset(h,0,sizeof h);
    memset(in_path,0,sizeof in_path);
    memset(chand,0,sizeof chand);
    tartib.clear();
    dfss.clear();
    for(ll i=0;i<maxn;i++){
	ger[i].clear();
	tree[i].clear();
    }
}
pii find_far(ll v){
    vis[v]=1;
    pii ans=mp(0,v);
    for(auto u:ger[v]){
	if(!vis[u]){
	    pii e=find_far(u);
	    e.F++;
	    ans=max(ans,e);
	}
    }
    return ans;
}
pair<pii,ll> find_rot(ll n,ll m){
    pii e=find_far(0);
    memset(vis,0,sizeof vis);
    pii r=find_far(e.S);
    memset(vis,0,sizeof vis);
    return mp(mp(r.S,e.S),r.F); 
}
bool  dfs(ll a,ll b){
    bool ans=0;
    if(a==b)ans=1;
    vis[a]=1;
    for(auto v:ger[a]){
	if(!vis[v]){
	    tree[a].pb(v);
	    ans|=dfs(v,b);
	}
    }
    in_path[a]=ans;
    return ans;
}
void dfs_2(ll a){
    tartib.pb(a);
    dfss.pb(a);
    if(!in_path[a])newras--;
    for(auto v:tree[a]){
	if(newras && in_path[v]==0){
	    dfs_2(v);
	    dfss.pb(a);
	}
    }
    for(auto v:tree[a]){
	if(in_path[v]){
	    dfs_2(v);
	}
    }
}
void make_tartib(pair<pii,ll> e){
    ll a=e.F.F;
    ll b=e.F.S;
    memset(vis,0,sizeof vis);
    dfs(a,b);
    newras=60-(e.S+1);
    dfs_2(a);
}
void bfs(ll a,ll x){
    memset(vis,0,sizeof vis);
    memset(h,0,sizeof h);
    queue<ll> qu;
    qu.push(a);
    vis[a]=1;
    h[a]=0;
    while(qu.size()){
	ll v=qu.front();
	qu.pop();
	ans[v]=((x>>(h[v]%60))&1);
	for(auto u:ger[v]){
	    if(!vis[u]){
		qu.push(u);
		vis[u]=1;
		h[u]=h[v]+1;
	    }
	}
    }
}

long long Ioi(int n, int m, int A[], int B[],int p,int v, int T){
    clearr();    
    for(ll i=0;i<m;i++){
	ger[A[i]].pb(B[i]);
	ger[B[i]].pb(A[i]);
    }
    pair<pii,ll> ew=find_rot(n,m);
    pii r=mp(ew.S,ew.F.F);
    if(r.F>=60){
	bfs(r.F);  
	while(h[p]%60!=0){
	    for(auto u:ger[p]){
		if(h[u]==h[p]-1){
		    v=move(u);
		    p=u;
		    break;
		}
	    }
	}
	if(h[p]==0){
	    while(h[p]%60!=59){
		ans[h[p]%60]=v;
		for(auto u:ger[p]){
		    if(h[u]==h[p]+1){
			v=move(u);
			p=u;
			break;
		    }
		}
	    }
	    ans[h[p]%60]=v;
	}else{
    	    for(ll i=0;i<60;i++){
		ans[h[p]%60]=v;
		for(auto u:ger[p]){
		    if(h[u]==h[p]-1){
			v=move(u);
			p=u;
			break;
		    }
		}
	    }
	    ans[h[p]%60]=v;
	}
	ll x=0;
	for(ll i=0;i<60;i++){
	    x+=(1LL<<i)*ans[i];
	}
	return x;
    }else{
	make_tartib(ew);
	while(h[p]!=0){
	    for(auto u:ger[p]){
		if(h[u]==h[p]-1){
		    v=move(u);
		    p=u;
		    break;
		}
	    }
	}
	for(ll i=0;i<tartib.size();i++){
	    chand[tartib[i]]=i+1;
	}
	if(chand[p]){
	    ans[chand[p]-1]=v;
	}
	for(ll i=1;i<dfss.size();i++){
	    v=move(dfss[i]);
	    p=dfss[i];
	    if(chand[p]){
		ans[chand[p]-1]=v;
	    }
	}
	ll x=0;
	for(ll i=0;i<60;i++){
	    x+=(1LL<<i)*ans[i];
	}
	return x;

    }
}

Compilation message

Joi.cpp: In function 'void clearr()':
Joi.cpp:34:12: error: 'chand' was not declared in this scope
     memset(chand,0,sizeof chand);
            ^~~~~
Joi.cpp:34:12: note: suggested alternative: 'srand'
     memset(chand,0,sizeof chand);
            ^~~~~
            srand
Joi.cpp: In function 'void bfs(long long int)':
Joi.cpp:109:11: error: 'x' was not declared in this scope
  ans[v]=((x>>(h[v]%60))&1);
           ^
Joi.cpp: In function 'void Joi(int, int, int*, int*, long long int, int)':
Joi.cpp:139:14: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(ll i=0;i<tartib.size();i++){
             ~^~~~~~~~~~~~~~
Joi.cpp:140:30: error: 'x' was not declared in this scope
      MessageBoard(tartib[i],(x>>i)&1);
                              ^

Ioi.cpp: In function 'long long int Ioi(int, int, int*, int*, int, int, int)':
Ioi.cpp:130:9: error: too few arguments to function 'void bfs(long long int, long long int)'
  bfs(r.F);  
         ^
Ioi.cpp:100:6: note: declared here
 void bfs(ll a,ll x){
      ^~~
Ioi.cpp:181:14: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(ll i=0;i<tartib.size();i++){
             ~^~~~~~~~~~~~~~
Ioi.cpp:187:14: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(ll i=1;i<dfss.size();i++){
             ~^~~~~~~~~~~~