This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
vector<int>top;
vector<int>adj[(int)2e5+5];
vector<int>region;
map<pair<int,int>,int>mp;
void dfs(int u, int e = -1) {
for(auto z : top) {
mp[{region[u],region[z]}]++;
}
top.push_back(u);
for(auto z : adj[u]) if(z != e) {
dfs(z,u);
}
top.pop_back();
}
signed main() {
int n,r,q; cin>>n>>r>>q;
region.resize(n);
int h; cin>>h; region[0] = h;
for(int i = 1 ; i < n ; i++) {
int s,h; cin>>s>>h;
s--;
adj[s].push_back(i);
region[i] = h;
}
dfs(0);
while(q--) {
int a,b; cin>>a>>b;
cout << flush << mp[{b,a}] << "\n";
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |