제출 #238304

#제출 시각아이디문제언어결과실행 시간메모리
238304Andrei_CotorBall Machine (BOI13_ballmachine)C++11
20.95 / 100
1095 ms18424 KiB
#include<iostream> #include<vector> #include<algorithm> #include<set> using namespace std; int P[20][100005]; vector<int> Sons[100005]; int Val[100005],Nr[100005]; bool Ball[100005]; set<pair<int,int> > S; void dfs(int nod) { Val[nod]=nod; for(auto son:Sons[nod]) { dfs(son); Val[nod]=min(Val[nod],Val[nod]); } } int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n,q; cin>>n>>q; int root=0; for(int i=1; i<=n; i++) { cin>>P[0][i]; Sons[P[0][i]].push_back(i); if(P[0][i]==0) root=i; } for(int i=1; i<=16; i++) { for(int j=1; j<=n; j++) P[i][j]=P[i-1][P[i-1][j]]; } dfs(root); for(int i=1; i<=n; i++) { if(Sons[i].size()==0) S.insert({Val[i],i}); } for(int i=1; i<=q; i++) { int tip,x; cin>>tip>>x; if(tip==1) { int rez=0; for(int j=1; j<=x; j++) //suma x-ilor va fi max n+q { int nod=(*S.begin()).second; S.erase(S.begin()); Ball[nod]=1; rez=nod; if(nod!=root) { int p=P[0][nod]; Nr[p]++; if(Nr[p]==Sons[p].size()) S.insert({Val[p],p}); } } cout<<rez<<"\n"; } else { int rez=0; for(int i=16; i>=0; i--) { if(Ball[P[i][x]]) { rez+=(1<<i); x=P[i][x]; } } cout<<rez<<"\n"; Ball[x]=0; if(x!=root) { int p=P[0][x]; if(Nr[p]==Sons[p].size()) { Nr[p]--; S.erase({Val[p],p}); } } S.insert({Val[x],x}); } } return 0; }

컴파일 시 표준 에러 (stderr) 메시지

ballmachine.cpp: In function 'int main()':
ballmachine.cpp:76:29: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
                     if(Nr[p]==Sons[p].size())
                        ~~~~~^~~~~~~~~~~~~~~~
ballmachine.cpp:101:25: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
                 if(Nr[p]==Sons[p].size())
                    ~~~~~^~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...