Submission #1128683

#TimeUsernameProblemLanguageResultExecution timeMemory
1128683rayan_bdRegions (IOI09_regions)C++20
0 / 100
179 ms196608 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*/ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); } vector<int> adj[mxN]; int region[mxN],dp[mxN][505],answers[505][505]; void dfs(int u){ for(auto it:adj[u]){ dfs(it); for(int i=0;i<=500;++i){ dp[u][i]+=dp[it][i]; } ++dp[u][region[it]]; } } int main(){ io(); int n,r,q,u,man,reg;cin>>n>>r>>q; cin>>region[1]; for(int i=2;i<=n;++i){ cin>>u>>region[i]; adj[u].pb(i); } memset(dp,0,sizeof(dp)); dfs(1); for(int i=1;i<=n;++i){ for(int j=1;j<=r;++j){ answers[region[i]][j]+=dp[i][j]; } } while(q--){ cin>>man>>reg; cout<<answers[man][reg]<<endl; } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...