#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;
int main(){
int n,r,q;
cin >> n >> r >> q;
vvi hijos(n+1);
vi regiones(n+1);
int a;
cin >> a;
regiones[1]=a;
for (int i=2;i<n+1;i++){
int a,b;
cin >> a >> b;
regiones[i]=b;
hijos[a].push_back(i);
}
vvi sol(r+1,vi(r+1,0));
for (int i=1;i<r+1;i++){
queue<pii> cola;
cola.push(pii{1,0});
while (cola.size()){
pii a=cola.front();
cola.pop();
sol[i][regiones[a.first]]+=a.second;
if (regiones[a.first]==i) a.second++;
for (int x:hijos[a.first]) cola.push(pii{x,a.second});
}
}
while (q--){
int a,b;
cin >> a >> b;
cout << sol[a][b] << endl;
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
200 KB |
Output is correct |
2 |
Correct |
1 ms |
200 KB |
Output is correct |
3 |
Correct |
2 ms |
200 KB |
Output is correct |
4 |
Correct |
6 ms |
200 KB |
Output is correct |
5 |
Correct |
7 ms |
328 KB |
Output is correct |
6 |
Correct |
23 ms |
584 KB |
Output is correct |
7 |
Correct |
36 ms |
468 KB |
Output is correct |
8 |
Correct |
32 ms |
512 KB |
Output is correct |
9 |
Correct |
111 ms |
928 KB |
Output is correct |
10 |
Correct |
181 ms |
1480 KB |
Output is correct |
11 |
Correct |
198 ms |
1472 KB |
Output is correct |
12 |
Correct |
308 ms |
2268 KB |
Output is correct |
13 |
Correct |
433 ms |
1776 KB |
Output is correct |
14 |
Correct |
259 ms |
2076 KB |
Output is correct |
15 |
Correct |
445 ms |
2880 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1276 ms |
4748 KB |
Output is correct |
2 |
Correct |
1562 ms |
4244 KB |
Output is correct |
3 |
Correct |
1919 ms |
5840 KB |
Output is correct |
4 |
Correct |
2858 ms |
64652 KB |
Output is correct |
5 |
Correct |
3958 ms |
100544 KB |
Output is correct |
6 |
Runtime error |
95 ms |
131076 KB |
Execution killed with signal 9 |
7 |
Runtime error |
109 ms |
131076 KB |
Execution killed with signal 9 |
8 |
Runtime error |
123 ms |
131076 KB |
Execution killed with signal 9 |
9 |
Runtime error |
171 ms |
131076 KB |
Execution killed with signal 9 |
10 |
Runtime error |
169 ms |
131076 KB |
Execution killed with signal 9 |
11 |
Runtime error |
188 ms |
131076 KB |
Execution killed with signal 9 |
12 |
Runtime error |
179 ms |
131076 KB |
Execution killed with signal 9 |
13 |
Runtime error |
186 ms |
131076 KB |
Execution killed with signal 9 |
14 |
Runtime error |
199 ms |
131076 KB |
Execution killed with signal 9 |
15 |
Runtime error |
216 ms |
131076 KB |
Execution killed with signal 9 |
16 |
Runtime error |
184 ms |
131076 KB |
Execution killed with signal 9 |
17 |
Runtime error |
187 ms |
131076 KB |
Execution killed with signal 9 |