#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;
for(int i=0;i<Q;i++){
cin>>a>>b;
a--;
b--;
if(bus[a][b]==0){
vector<bool>vi(N,false);
dfs(0,g,vi,bus[a],0,a);
}
cout<<bus[a][b]<<"\n";
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
200 KB |
Output is correct |
2 |
Incorrect |
1 ms |
200 KB |
Output isn't correct |
3 |
Incorrect |
3 ms |
200 KB |
Output isn't correct |
4 |
Incorrect |
6 ms |
200 KB |
Output isn't correct |
5 |
Incorrect |
6 ms |
328 KB |
Output isn't correct |
6 |
Incorrect |
24 ms |
584 KB |
Output isn't correct |
7 |
Incorrect |
64 ms |
456 KB |
Output isn't correct |
8 |
Incorrect |
74 ms |
584 KB |
Output isn't correct |
9 |
Correct |
77 ms |
1224 KB |
Output is correct |
10 |
Incorrect |
933 ms |
1500 KB |
Output isn't correct |
11 |
Incorrect |
223 ms |
1480 KB |
Output isn't correct |
12 |
Correct |
317 ms |
2504 KB |
Output is correct |
13 |
Incorrect |
5113 ms |
1820 KB |
Output isn't correct |
14 |
Correct |
364 ms |
1992 KB |
Output is correct |
15 |
Correct |
350 ms |
6000 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1120 ms |
5912 KB |
Output is correct |
2 |
Incorrect |
1541 ms |
4400 KB |
Output isn't correct |
3 |
Correct |
1696 ms |
8580 KB |
Output is correct |
4 |
Incorrect |
4521 ms |
64656 KB |
Output isn't correct |
5 |
Incorrect |
2983 ms |
102496 KB |
Output isn't correct |
6 |
Runtime error |
96 ms |
131076 KB |
Execution killed with signal 9 |
7 |
Runtime error |
99 ms |
131076 KB |
Execution killed with signal 9 |
8 |
Runtime error |
123 ms |
131076 KB |
Execution killed with signal 9 |
9 |
Runtime error |
165 ms |
131076 KB |
Execution killed with signal 9 |
10 |
Runtime error |
181 ms |
131076 KB |
Execution killed with signal 9 |
11 |
Runtime error |
204 ms |
131076 KB |
Execution killed with signal 9 |
12 |
Runtime error |
193 ms |
131076 KB |
Execution killed with signal 9 |
13 |
Runtime error |
194 ms |
131076 KB |
Execution killed with signal 9 |
14 |
Runtime error |
204 ms |
131076 KB |
Execution killed with signal 9 |
15 |
Runtime error |
189 ms |
131076 KB |
Execution killed with signal 9 |
16 |
Runtime error |
193 ms |
131076 KB |
Execution killed with signal 9 |
17 |
Runtime error |
194 ms |
131072 KB |
Execution killed with signal 9 |