이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "bits/stdc++.h"
#define MAXN 100009
#define INF 1000000007
#define mp(x,y) make_pair(x,y)
#define all(v) v.begin(),v.end()
#define pb(x) push_back(x)
#define wr cout<<"----------------"<<endl;
#define ppb() pop_back()
#define tr(ii,c) for(__typeof((c).begin()) ii=(c).begin();ii!=(c).end();ii++)
#define ff first
#define ss second
#define my_little_dodge 46
#define debug(x) cerr<< #x <<" = "<< x<<endl;
using namespace std;
typedef long long ll;
typedef pair<int,int> PII;
template<class T>bool umin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
template<class T>bool umax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
vector<int>adj[MAXN];
int dp[MAXN],id[MAXN],cnt,P[MAXN][18],vis[MAXN],n;
set<PII>s;
bool cmp(int x,int y){
return (dp[x]<dp[y]);
}
void pre(int nd){
dp[nd]=nd;
if(adj[nd].size()==0)
return;
tr(it,adj[nd])
pre(*it),umin(dp[nd],dp[*it]);
sort(all(adj[nd]),cmp);
}
vector<int>v;
void dfs(int nd){
tr(it,adj[nd])
P[*it][0]=nd,dfs(*it);
id[nd]=++cnt;
}
void build(){
for(int j=1;j<=17;j++)
for(int i=1;i<=n;i++)
if(~P[i][j-1])
P[i][j]=P[P[i][j-1]][j-1];
}
int main(){
memset(P,-1,sizeof P);
//~ freopen("file.in", "r", stdin);
int q,root;
scanf("%d%d",&n,&q);
for(int i=1;i<=n;i++){
int p;
scanf("%d",&p);
if(!p)
root=i;
else
adj[p].pb(i);
}
pre(root);dfs(root);
build();
for(int i=1;i<=n;i++)
s.insert(mp(id[i],i));
while(q--){
int t,k,ans=0;
scanf("%d%d",&t,&k);
if(t==1){
__typeof((s).begin())it=s.begin();
while(k--){
vis[it->ss]=1;
ans=it->ss;
s.erase(it++);
}
}
else{
for(int j=17;j>=0;j--)
if(~P[k][j] and vis[P[k][j]])
k=P[k][j],ans+=(1<<j);
vis[k]=0;
s.insert(mp(id[k],k));
}
printf("%d\n",ans);
}
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
ballmachine.cpp: In function 'int main()':
ballmachine.cpp:50:24: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d",&n,&q);
^
ballmachine.cpp:53:17: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d",&p);
^
ballmachine.cpp:65:22: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d",&t,&k);
^
# | 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... |