# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1083271 | rayan_bd | Regions (IOI09_regions) | C++17 | 246 ms | 131072 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;
#define pb push_back
#define ll long long
const int mxN = 2e5 + 5000;
ll color[mxN][505];
vector<ll> adj[mxN];
ll hd[mxN],out[mxN];
unordered_map<ll,vector<ll>> mp;
void solve(ll tc) {
ll n,r,q,r1,r2,super;cin>>n>>r>>q;
cin>>hd[1];
mp[hd[1]].pb(1);
color[1][hd[1]]=1;
for(ll i=2;i<=n;++i){
cin>>super>>hd[i];
adj[i].pb(super);
mp[hd[i]].pb(i);
color[i][hd[i]]=1;
++out[super];
}
set<ll> st;
for(ll i=1;i<=n;++i){
if(out[i]==0){
st.insert(i);
}
}
while(st.size()){
ll u=*st.begin();
st.erase(u);
for(auto it:adj[u]){
for(ll i=1;i<505;++i){
color[it][i]+=color[u][i];
}
if(--out[it]==0) st.insert(it);
}
}
while(q--){
cin>>r1>>r2;
ll ans=0;
for(auto it:mp[hd[r1]]){
ans+=color[it][r2];
}
cout.flush()<<ans<<'\n';
cout.flush();
}
}
void testing(){
#ifndef ONLINE_JUDGE
freopen("input.in","r",stdin);
freopen("output.out","w",stdout);
#endif
}
int main() {
//testing();
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
solve(0);
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |