Submission #666875

#TimeUsernameProblemLanguageResultExecution timeMemory
666875Hacv16Ball Machine (BOI13_ballmachine)C++17
0 / 100
1 ms596 KiB
#include<bits/stdc++.h> using namespace std; typedef long long ll; const int MAX = 450; const int INF = 0x3f3f3f3f; int n, q, filled[MAX], add, root, ans; vector<int> adj[MAX]; void dfs(int u, int p){ for(auto v : adj[u]){ if(v == p) continue; if(!filled[v]) dfs(v, u); } if(add && !filled[u]) filled[u] = true, ans = u, add--; } int main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); cin >> n >> q; for(int i = 1; i <= n; i++){ int x; cin >> x; if(x != 0){ adj[x].push_back(i); adj[i].push_back(x); }else{ root = i; } } for(int i = 1; i <= n; i++) sort(adj[i].begin(), adj[i].end()); while(q--){ int op, k; cin >> op >> k; if(op == 1){ add = k; ans = root; dfs(root, -1); cout << ans << '\n'; }else{ cout << rand() << '\n'; } } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...