/* Author : Mychecksdead */
#include<bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
typedef long long int ll;
typedef long double ld;
#define MOD (1000000000+7)
#define MOD1 (998244353)
#define PI 3.1415926535
#define pb push_back
#define setp() cout << setprecision(15)
#define all(x) x.begin(), x.end()
#define debug(x) cerr << #x << " is " << x << '\n';
const int N = 1e6+100, M = 1e5+10, F = 2147483646, K = 20;
int n, q, r, a[N], ans[1000][1000];
vector<int> g[N], R[N];
void dfs(int v, int p){
R[v].resize(r + 5);
for(int u: g[v]){
if(u == p) continue;
dfs(u, v);
for(int j = 1; j <= r; ++j) R[v][j] += R[u][j];
}
for(int j = 1; j <= r; ++j) ans[a[v]][j] += R[v][j];
R[v][a[v]]++;
}
void solve(){
cin >> n >> r >> q;
cin >> a[1];
for(int i = 2; i <= n; ++i){
int x; cin >> x >> a[i];
g[x].pb(i);
g[i].pb(x);
}
for(int i = 0; i <= r; ++i) for(int j = 0; j <= r; ++j) ans[i][j] = 0;
dfs(1, 1);
for(;q--;){
int a, b; cin >> a >> b;
cout << ans[a][b] << endl;
}
}
int main(){
cin.tie(0); ios::sync_with_stdio(0);
int T = 1, aa;
// cin >> T;aa=T;
while(T--){
// cout << "Case #" << aa-T << ": ";
solve();
cout << '\n';
}
return 0;
}
Compilation message
regions.cpp: In function 'int main()':
regions.cpp:54:16: warning: unused variable 'aa' [-Wunused-variable]
54 | int T = 1, aa;
| ^~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
25 ms |
47208 KB |
Execution killed with signal 13 |
2 |
Runtime error |
24 ms |
47312 KB |
Execution killed with signal 13 |
3 |
Runtime error |
28 ms |
47284 KB |
Execution killed with signal 13 |
4 |
Runtime error |
29 ms |
47368 KB |
Execution killed with signal 13 |
5 |
Runtime error |
29 ms |
47588 KB |
Execution killed with signal 13 |
6 |
Runtime error |
33 ms |
49168 KB |
Execution killed with signal 13 |
7 |
Runtime error |
47 ms |
48896 KB |
Execution killed with signal 13 |
8 |
Runtime error |
57 ms |
49792 KB |
Execution killed with signal 13 |
9 |
Runtime error |
84 ms |
55048 KB |
Execution killed with signal 13 |
10 |
Runtime error |
110 ms |
65992 KB |
Execution killed with signal 13 |
11 |
Runtime error |
137 ms |
65360 KB |
Execution killed with signal 13 |
12 |
Runtime error |
219 ms |
86116 KB |
Execution killed with signal 13 |
13 |
Runtime error |
195 ms |
82144 KB |
Execution killed with signal 13 |
14 |
Runtime error |
185 ms |
73540 KB |
Execution killed with signal 13 |
15 |
Runtime error |
216 ms |
91596 KB |
Execution killed with signal 13 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
816 ms |
112932 KB |
Execution killed with signal 13 |
2 |
Runtime error |
972 ms |
122604 KB |
Execution killed with signal 13 |
3 |
Runtime error |
128 ms |
131072 KB |
Execution killed with signal 9 |
4 |
Runtime error |
84 ms |
113404 KB |
Execution killed with signal 11 |
5 |
Runtime error |
81 ms |
113860 KB |
Execution killed with signal 11 |
6 |
Runtime error |
86 ms |
114852 KB |
Execution killed with signal 11 |
7 |
Runtime error |
99 ms |
116020 KB |
Execution killed with signal 11 |
8 |
Runtime error |
97 ms |
117864 KB |
Execution killed with signal 11 |
9 |
Runtime error |
111 ms |
121048 KB |
Execution killed with signal 11 |
10 |
Runtime error |
123 ms |
122308 KB |
Execution killed with signal 11 |
11 |
Runtime error |
134 ms |
124832 KB |
Execution killed with signal 11 |
12 |
Runtime error |
147 ms |
123580 KB |
Execution killed with signal 11 |
13 |
Runtime error |
126 ms |
123676 KB |
Execution killed with signal 11 |
14 |
Runtime error |
135 ms |
124344 KB |
Execution killed with signal 11 |
15 |
Runtime error |
133 ms |
124220 KB |
Execution killed with signal 11 |
16 |
Runtime error |
127 ms |
124260 KB |
Execution killed with signal 11 |
17 |
Runtime error |
136 ms |
124252 KB |
Execution killed with signal 11 |