#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'
const int MXN = 200000, MXR = 25000, INF = 1e9+1;
int n, r, q;
int reg[MXN+1], tin[MXN+1], tout[MXN+1], seen[MXR+1][MXR+1], pt = 0;
vi adj[MXN+1];
vector<vi> regList[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, 0, r) for_(j, 0, r) seen[i][j] = -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][r2] != -1) {
cout << seen[r1][r2] << endl;
continue;
}
//cout << r1 << " " << r2 << endl;
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});
//cout << ptb-pta << endl;
ans += ptb-pta;
}
cout << ans << endl;
seen[r1][r2] = ans;
}
return 0;
}
Compilation message
/tmp/ccPBfTw9.o: In function `dfs(int, int)':
regions.cpp:(.text+0xb5): relocation truncated to fit: R_X86_64_32S against symbol `reg' defined in .bss section in /tmp/ccPBfTw9.o
regions.cpp:(.text+0x14b): relocation truncated to fit: R_X86_64_32S against symbol `tin' defined in .bss section in /tmp/ccPBfTw9.o
regions.cpp:(.text+0x195): relocation truncated to fit: R_X86_64_32S against symbol `tout' defined in .bss section in /tmp/ccPBfTw9.o
/tmp/ccPBfTw9.o: In function `main':
regions.cpp:(.text.startup+0x32): relocation truncated to fit: R_X86_64_PC32 against symbol `std::cin' defined in .bss._ZSt3cin section in /usr/lib/gcc/x86_64-linux-gnu/9/libstdc++.a(globals_io.o)
regions.cpp:(.text.startup+0x6a): relocation truncated to fit: R_X86_64_PC32 against symbol `r' defined in .bss section in /tmp/ccPBfTw9.o
regions.cpp:(.text.startup+0x70): relocation truncated to fit: R_X86_64_PC32 against symbol `reg' defined in .bss section in /tmp/ccPBfTw9.o
regions.cpp:(.text.startup+0xc2): relocation truncated to fit: R_X86_64_PC32 against symbol `n' defined in .bss section in /tmp/ccPBfTw9.o
regions.cpp:(.text.startup+0xfe): relocation truncated to fit: R_X86_64_PC32 against symbol `n' defined in .bss section in /tmp/ccPBfTw9.o
regions.cpp:(.text.startup+0x218): relocation truncated to fit: R_X86_64_PC32 against symbol `q' defined in .bss section in /tmp/ccPBfTw9.o
regions.cpp:(.text.startup+0x226): relocation truncated to fit: R_X86_64_PC32 against symbol `q' defined in .bss section in /tmp/ccPBfTw9.o
regions.cpp:(.text.startup+0x281): additional relocation overflows omitted from the output
collect2: error: ld returned 1 exit status