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 <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <utility>
#include <queue>
#include <map>
#include <iomanip>
using namespace std;
vector<int>region;
void dfs(int nodo,vector<vector<int> >&g,vector<bool>&vi,vector<int>&b,int x,int a){
vi[nodo]=true;
b[region[nodo]]+=x;
if(region[nodo]==a)x++;
for(int c:g[nodo]){
if(!vi[c]){
dfs(c,g,vi,b,x,a);
}
}
}
int main(){
int N,R,Q;
cin>>N>>R>>Q;
vector<vector<int> >g(N);
g.clear();
region.resize(N);
int a,b;
cin>>a;
a--;
region[0]=a;
for(int i=1;i<N;i++){
cin>>a>>b;
a--;
b--;
region[i]=b;
g[a].push_back(i);
}
vector<vector<int> >bus(R);
vector<int>vacio(R,0);
for(int i=0;i<R;i++)bus[i]=vacio;
vector<bool>rv(N,false);
for(int i=0;i<N;i++){
int j=region[i];
if(!rv[j]){
rv[j]=true;
vector<bool>vi(N,false);
dfs(0,g,vi,bus[j],0,j);
}
}
for(int i=0;i<Q;i++){
cin>>a>>b;
a--;
b--;
cout<<bus[a][b]<<"\n";
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |