#include <bits/stdc++.h>
using namespace std;
#define fast ios::sync_with_stdio(0);cin.tie(0);
typedef long long ll;
#define f first
#define s second
#define MOD 1000000007
#define LOGN 20
#define MAXN 200005
#define pb push_back
vector<vector<int>> graph;
int region[MAXN];
int ans[505][505], cnt[505][505];
void dfs(int node, int parent) {
for (int i = 0; i <= 500; i++) {
cnt[node][i] = cnt[parent][i];
ans[i][region[node]] += cnt[node][i];
}
cnt[node][region[node]]++;
for (auto u : graph[node]) {
dfs(u, node);
}
}
int main() {
fast
int N, R, Q, S, r1, r2;
cin >> N >> R >> Q >> region[1];
graph = vector<vector<int>>(N+1, vector<int>());
for (int i = 2; i <= N; i++) {
cin >> S >> region[i];
graph[S].pb(i);
}
if (R <= 500) {
dfs(1, 1);
while (Q--) {
cin >> r1 >> r2;
cout << ans[r1][r2] << endl;
}
} else {
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1232 KB |
Output is correct |
2 |
Correct |
1 ms |
1360 KB |
Output is correct |
3 |
Correct |
2 ms |
1360 KB |
Output is correct |
4 |
Correct |
5 ms |
1616 KB |
Output is correct |
5 |
Correct |
4 ms |
2256 KB |
Output is correct |
6 |
Incorrect |
13 ms |
2384 KB |
Output isn't correct |
7 |
Runtime error |
6 ms |
5320 KB |
Execution killed with signal 11 |
8 |
Runtime error |
4 ms |
4816 KB |
Execution killed with signal 11 |
9 |
Runtime error |
7 ms |
6696 KB |
Execution killed with signal 11 |
10 |
Runtime error |
5 ms |
4560 KB |
Execution killed with signal 11 |
11 |
Runtime error |
7 ms |
6224 KB |
Execution killed with signal 11 |
12 |
Runtime error |
8 ms |
8112 KB |
Execution killed with signal 11 |
13 |
Runtime error |
6 ms |
4816 KB |
Execution killed with signal 11 |
14 |
Runtime error |
9 ms |
7376 KB |
Execution killed with signal 11 |
15 |
Runtime error |
12 ms |
10576 KB |
Execution killed with signal 11 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
20 ms |
13588 KB |
Execution killed with signal 11 |
2 |
Runtime error |
19 ms |
12512 KB |
Execution killed with signal 11 |
3 |
Runtime error |
21 ms |
15852 KB |
Execution killed with signal 11 |
4 |
Incorrect |
5 ms |
1872 KB |
Unexpected end of file - int32 expected |
5 |
Incorrect |
6 ms |
2448 KB |
Unexpected end of file - int32 expected |
6 |
Incorrect |
10 ms |
3024 KB |
Unexpected end of file - int32 expected |
7 |
Incorrect |
11 ms |
4004 KB |
Unexpected end of file - int32 expected |
8 |
Incorrect |
18 ms |
6080 KB |
Unexpected end of file - int32 expected |
9 |
Incorrect |
24 ms |
8676 KB |
Unexpected end of file - int32 expected |
10 |
Incorrect |
43 ms |
10260 KB |
Unexpected end of file - int32 expected |
11 |
Incorrect |
34 ms |
9308 KB |
Unexpected end of file - int32 expected |
12 |
Incorrect |
42 ms |
11288 KB |
Unexpected end of file - int32 expected |
13 |
Incorrect |
31 ms |
10824 KB |
Unexpected end of file - int32 expected |
14 |
Incorrect |
41 ms |
10848 KB |
Unexpected end of file - int32 expected |
15 |
Incorrect |
40 ms |
11952 KB |
Unexpected end of file - int32 expected |
16 |
Incorrect |
41 ms |
11932 KB |
Unexpected end of file - int32 expected |
17 |
Incorrect |
34 ms |
12032 KB |
Unexpected end of file - int32 expected |