#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
const int nax = 2e5 + 50;
const int rax = 510;
int r[nax],ans[rax][rax];
int n,R,q;
vector<int> g[nax];
vector<int> dfs(int u,int p){
vector<int> cur(R+1);
for(int v : g[u]){
if(v == p)
continue;
vector<int> tmp = dfs(v,u);
cur[r[v]]++;
for(int i=1;i<=R;i++)
cur[i] += tmp[i];
}
for(int i=1;i<=R;i++)
ans[r[u]][i] += cur[i];
return cur;
}
int main(){
cin>>n>>R>>q;
cin>>r[1];
for(int i=2;i<=n;i++){
int p;
cin>>p>>r[i];
g[p].push_back(i);
}
dfs(1,0);
int a,b;
for(int i=0;i<q;i++){
cin>>a>>b;
cout << ans[a][b] << endl;
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
4992 KB |
Output is correct |
2 |
Correct |
6 ms |
5120 KB |
Output is correct |
3 |
Correct |
12 ms |
4992 KB |
Output is correct |
4 |
Correct |
12 ms |
5120 KB |
Output is correct |
5 |
Correct |
15 ms |
5120 KB |
Output is correct |
6 |
Correct |
26 ms |
6384 KB |
Output is correct |
7 |
Correct |
38 ms |
5504 KB |
Output is correct |
8 |
Correct |
39 ms |
5760 KB |
Output is correct |
9 |
Correct |
62 ms |
12060 KB |
Output is correct |
10 |
Correct |
100 ms |
6528 KB |
Output is correct |
11 |
Correct |
139 ms |
6876 KB |
Output is correct |
12 |
Correct |
219 ms |
14984 KB |
Output is correct |
13 |
Correct |
176 ms |
6240 KB |
Output is correct |
14 |
Correct |
158 ms |
6648 KB |
Output is correct |
15 |
Correct |
273 ms |
49416 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
822 ms |
21344 KB |
Output is correct |
2 |
Correct |
898 ms |
9268 KB |
Output is correct |
3 |
Correct |
1279 ms |
48596 KB |
Output is correct |
4 |
Runtime error |
36 ms |
12152 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
5 |
Runtime error |
86 ms |
19288 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
6 |
Runtime error |
56 ms |
14200 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
7 |
Runtime error |
86 ms |
14672 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
8 |
Runtime error |
192 ms |
131072 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
9 |
Runtime error |
218 ms |
58872 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
10 |
Runtime error |
217 ms |
131072 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
11 |
Runtime error |
233 ms |
21624 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
12 |
Runtime error |
243 ms |
67036 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
13 |
Runtime error |
225 ms |
81528 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
14 |
Runtime error |
214 ms |
24952 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
15 |
Runtime error |
293 ms |
131072 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
16 |
Runtime error |
240 ms |
131072 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
17 |
Runtime error |
243 ms |
111388 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |