#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);
vector<short> 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 |
3 ms |
200 KB |
Output is correct |
4 |
Correct |
4 ms |
200 KB |
Output is correct |
5 |
Correct |
5 ms |
328 KB |
Output is correct |
6 |
Correct |
27 ms |
584 KB |
Output is correct |
7 |
Correct |
18 ms |
456 KB |
Output is correct |
8 |
Correct |
54 ms |
456 KB |
Output is correct |
9 |
Correct |
99 ms |
912 KB |
Output is correct |
10 |
Correct |
178 ms |
1480 KB |
Output is correct |
11 |
Correct |
179 ms |
1412 KB |
Output is correct |
12 |
Correct |
249 ms |
2248 KB |
Output is correct |
13 |
Correct |
387 ms |
1736 KB |
Output is correct |
14 |
Correct |
249 ms |
2040 KB |
Output is correct |
15 |
Correct |
410 ms |
2824 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
763 ms |
4636 KB |
Output is correct |
2 |
Correct |
1489 ms |
4096 KB |
Output is correct |
3 |
Correct |
1842 ms |
5744 KB |
Output is correct |
4 |
Correct |
2674 ms |
64588 KB |
Output is correct |
5 |
Correct |
3962 ms |
100588 KB |
Output is correct |
6 |
Runtime error |
103 ms |
131076 KB |
Execution killed with signal 9 |
7 |
Runtime error |
108 ms |
131076 KB |
Execution killed with signal 9 |
8 |
Runtime error |
119 ms |
131076 KB |
Execution killed with signal 9 |
9 |
Runtime error |
152 ms |
131076 KB |
Execution killed with signal 9 |
10 |
Runtime error |
185 ms |
131076 KB |
Execution killed with signal 9 |
11 |
Runtime error |
192 ms |
131076 KB |
Execution killed with signal 9 |
12 |
Runtime error |
183 ms |
131076 KB |
Execution killed with signal 9 |
13 |
Runtime error |
179 ms |
131076 KB |
Execution killed with signal 9 |
14 |
Runtime error |
192 ms |
131076 KB |
Execution killed with signal 9 |
15 |
Runtime error |
192 ms |
131076 KB |
Execution killed with signal 9 |
16 |
Runtime error |
240 ms |
131076 KB |
Execution killed with signal 9 |
17 |
Runtime error |
201 ms |
131076 KB |
Execution killed with signal 9 |