# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
989124 | SuPythony | Ball Machine (BOI13_ballmachine) | C++17 | 1101 ms | 17500 KiB |
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 <bits/stdc++.h>
using namespace std;
typedef long long ll;
vector<vector<int>> al, ral;
vector<int> mn;
vector<int> ball;
int root;
void mndfs(int u) {
mn[u]=u;
for (int v: al[u]) {
mndfs(v);
mn[u]=min(mn[u],mn[v]);
}
}
int add_ball() {
int curr=root;
while (true) {
int n=-1;
int cmn=1e9;
for (int v: al[curr]) {
if (mn[v]<cmn&&!ball[v]) {
cmn=mn[v];
n=v;
}
}
if (n==-1) {
ball[curr]=1;
return curr;
}
curr=n;
}
}
int main() {
int n, q; cin>>n>>q;
al.assign(n+1,vector<int>());
ral.assign(n+1,vector<int>());
mn.assign(n+1,1e9);
ball.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);
ral[i].push_back(p);
}
}
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;
cout<<0<<"\n";
}
}
return 0;
}
Compilation message (stderr)
# | 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... |