이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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... |