# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
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;
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |