#include <bits/stdc++.h>
using namespace std;
#define for_(i, s, e) for (int i = s; i < (int) e; i++)
#define for__(i, s, e) for (ll i = s; i < e; i++)
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> ii;
//#define endl '\n'
//struct pair_hash
//{
//template <class T1, class T2>
//std::size_t operator() (const std::pair<T1, T2> &pair) const
//{
//return std::hash<T1>()(pair.first) ^ std::hash<T2>()(pair.second);
//}
//};
const int MXN = 200000, MXR = 25000, INF = 1e9+1;
int n, r, q;
int reg[MXN+1], tin[MXN+1], tout[MXN+1], pt = 0;
vi adj[MXN+1];
vector<vi> regList[MXR+1];
unordered_map<int, int> seen[MXR+1];
void dfs(int p, int parent) {
regList[reg[p]].push_back({pt, p});
tin[p] = pt++;
for (int i: adj[p]) if (i != parent) dfs(i, p);
tout[p] = pt-1;
}
int main() {
#ifdef shiven
freopen("test.in", "r", stdin);
#endif
ios_base::sync_with_stdio(false);
cin.tie(0);
cin >> n >> r >> q;
cin >> reg[0];
reg[0] -= 1;
for_(i, 1, n) {
int p; cin >> p >> reg[i];
reg[i] -= 1;
adj[p-1].push_back(i);
}
dfs(0, 0);
while (q--) {
int r1, r2; cin >> r1 >> r2;
r1 -= 1; r2 -= 1;
if (seen[r1].count(r2)) {
assert(false);
continue;
}
int ans = 0;
for (auto i: regList[r1]) {
auto pta = lower_bound(regList[r2].begin(), regList[r2].end(), (vi) {tin[i[1]]+1, -1});
auto ptb = upper_bound(regList[r2].begin(), regList[r2].end(), (vi) {tout[i[1]], INF});
ans += ptb-pta;
}
cout << ans << endl;
seen[r1][r2] = ans;
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
14 ms |
14080 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Runtime error |
14 ms |
13984 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
3 |
Runtime error |
14 ms |
13976 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
4 |
Runtime error |
18 ms |
14112 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
5 |
Runtime error |
14 ms |
14196 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
6 |
Runtime error |
18 ms |
14336 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
7 |
Runtime error |
21 ms |
14336 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
8 |
Runtime error |
18 ms |
14592 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
9 |
Runtime error |
28 ms |
15992 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
10 |
Runtime error |
25 ms |
16120 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
11 |
Runtime error |
23 ms |
17272 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
12 |
Runtime error |
30 ms |
19192 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
13 |
Runtime error |
43 ms |
18936 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
14 |
Runtime error |
48 ms |
20860 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
15 |
Runtime error |
81 ms |
29432 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
66 ms |
31728 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Runtime error |
67 ms |
29380 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
3 |
Runtime error |
79 ms |
38124 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
4 |
Runtime error |
302 ms |
21496 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
5 |
Runtime error |
95 ms |
26232 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
6 |
Runtime error |
46 ms |
25080 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
7 |
Runtime error |
61 ms |
29304 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
8 |
Runtime error |
112 ms |
45816 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
9 |
Runtime error |
358 ms |
50708 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
10 |
Runtime error |
440 ms |
64120 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
11 |
Runtime error |
336 ms |
52252 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
12 |
Runtime error |
1579 ms |
54896 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
13 |
Runtime error |
4643 ms |
56388 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
14 |
Runtime error |
1785 ms |
55892 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
15 |
Runtime error |
1474 ms |
67560 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
16 |
Runtime error |
1058 ms |
85432 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
17 |
Runtime error |
259 ms |
82732 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |