제출 #989141

#제출 시각아이디문제언어결과실행 시간메모리
989141SuPythonyBall Machine (BOI13_ballmachine)C++17
7.54 / 100
1093 ms19592 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; vector<vector<int>> al; vector<int> par; vector<int> mn; vector<int> ball; vector<int> down; vector<int> order; set<pair<int,int>> next_node; int root,n; void dfs(int u) { for (int v: al[u]) { dfs(v); } order[u]=next_node.size()+1; next_node.insert({order[u],u}); } void mndfs(int u) { down[u]=-1; for (int v: al[u]) { mndfs(v); if (mn[v]<mn[u]) { down[u]=v; mn[u]=mn[v]; } } mn[u]=min(mn[u],u); } int add_ball() { auto b=*next_node.begin(); next_node.erase(next_node.begin()); ball[b.second]=1; return b.second; } int main() { int q; cin>>n>>q; al.assign(n+1,vector<int>()); par.assign(n+1,-1); mn.assign(n+1,1e9); ball.assign(n+1,0); down.assign(n+1,0); order.assign(n+1,0); for (int i=1; i<=n; i++) { int p; cin>>p; if (p==0) { root=i; } else { al[p].push_back(i); par[i]=p; } } for (int i=1; i<=n; i++) { sort(al[i].begin(),al[i].end()); } dfs(root); //mndfs(root); while (q--) { int t; cin>>t; if (t==1) { int k; cin>>k; int ans; for (int i=0; i<k; i++) { ans=add_ball(); } cout<<ans<<"\n"; } else { int x; cin>>x; ball[x]=0; next_node.insert({order[x],x}); cout<<0<<"\n"; } } return 0; }

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

ballmachine.cpp: In function 'int main()':
ballmachine.cpp:71:24: warning: 'ans' may be used uninitialized in this function [-Wmaybe-uninitialized]
   71 |             cout<<ans<<"\n";
      |                        ^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...