이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;
int main(){
int n,r,q;
cin >> n >> r >> q;
vvi hijos(n+1);
vector<short> regiones(n+1);
int a;
cin >> a;
regiones[1]=a;
for (int i=2;i<n+1;i++){
int a,b;
cin >> a >> b;
regiones[i]=b;
hijos[a].push_back(i);
}
vvi sol(r+1,vi(r+1,0));
for (int i=1;i<r+1;i++){
queue<pii> cola;
cola.push(pii{1,0});
while (cola.size()){
pii a=cola.front();
cola.pop();
sol[i][regiones[a.first]]+=a.second;
if (regiones[a.first]==i) a.second++;
for (int x:hijos[a.first]) cola.push(pii{x,a.second});
}
}
while (q--){
int a,b;
cin >> a >> b;
cout << sol[a][b] << endl;
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |