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>
#define ll long long
#define ft(n,i) for (ll i=0;i<n;i++)
#define tft(n,l,i) for (ll i=l;i<n;i++)
#define vi vector<ll>
using namespace std;
vi h,s;
vector<vi > graph;
ll to[510][510], most[510];
void bej(ll x)
{
most[h[x]]++;
ft (510,i) to[i][h[x]]+=most[i];
for (ll f: graph[x])
{
bej(f);
}
most[h[x]]--;
}
int main()
{
ios::sync_with_stdio(0);
ll n,r,q; cin>>n>>r>>q; h.assign(n+1,0); s.assign(n+1,0);
graph.assign(n+1,vi());
cin>>h[1];
tft(n+1,2,i)
{
cin>>s[i]>>h[i];
graph[s[i]].push_back(i);
}
bej(1);
ft (q,i)
{
ll a,b; cin>>a>>b; cout<<to[a][b]<<endl;
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |