# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1128692 | rayan_bd | Regions (IOI09_regions) | C++20 | 159 ms | 196608 KiB |
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define all(x) x.begin(),x.end()
const int mxN = 2e5+5000;
void io(){
#ifndef ONLINE_JUDGE
freopen("input.in","r",stdin);
freopen("output.out","w",stdout);
#endif
}
vector<int> adj[mxN];
int dp[mxN][505];
void dfs(int u){
for(auto it:adj[u]){
dfs(it);
for(int i=1;i<=500;++i){
dp[u][i]+=dp[it][i];
}
}
}
int main(){
// io();
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
memset(dp,0,sizeof(dp));
int n,r,q,u,man,reg;cin>>n>>r>>q;
cin>>u;
++dp[1][u];
dp[1][0]=u;
for(int i=2;i<=n;++i){
cin>>u>>man;
adj[u].pb(i);
++dp[i][man];
dp[i][0]=man;
}
dfs(1);
while(q--){
cin>>man>>reg;
int ans=0;
for(int i=1;i<=n;++i){
if(dp[i][0]!=man) continue;
ans+=dp[i][reg];
}
cout<<ans<<endl;
}
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |