#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<N;i++){
int j=region[i];
if(bus[j][j]==0){
vector<bool>vi(N,false);
dfs(i,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 |
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 |
5 ms |
280 KB |
Output isn't correct |
5 |
Incorrect |
9 ms |
328 KB |
Output isn't correct |
6 |
Correct |
22 ms |
584 KB |
Output is correct |
7 |
Incorrect |
31 ms |
456 KB |
Output isn't correct |
8 |
Incorrect |
26 ms |
584 KB |
Output isn't correct |
9 |
Correct |
72 ms |
1224 KB |
Output is correct |
10 |
Incorrect |
100 ms |
1480 KB |
Output isn't correct |
11 |
Incorrect |
157 ms |
1480 KB |
Output isn't correct |
12 |
Incorrect |
224 ms |
2648 KB |
Output isn't correct |
13 |
Incorrect |
161 ms |
1700 KB |
Output isn't correct |
14 |
Incorrect |
186 ms |
1968 KB |
Output isn't correct |
15 |
Correct |
350 ms |
6000 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1002 ms |
5912 KB |
Output isn't correct |
2 |
Incorrect |
1294 ms |
4448 KB |
Output isn't correct |
3 |
Incorrect |
1399 ms |
8644 KB |
Output isn't correct |
4 |
Incorrect |
700 ms |
64780 KB |
Output isn't correct |
5 |
Incorrect |
1182 ms |
102620 KB |
Output isn't correct |
6 |
Runtime error |
103 ms |
131076 KB |
Execution killed with signal 9 |
7 |
Runtime error |
104 ms |
131076 KB |
Execution killed with signal 9 |
8 |
Runtime error |
123 ms |
131076 KB |
Execution killed with signal 9 |
9 |
Runtime error |
167 ms |
131076 KB |
Execution killed with signal 9 |
10 |
Runtime error |
171 ms |
131076 KB |
Execution killed with signal 9 |
11 |
Runtime error |
194 ms |
131076 KB |
Execution killed with signal 9 |
12 |
Runtime error |
196 ms |
131076 KB |
Execution killed with signal 9 |
13 |
Runtime error |
184 ms |
131076 KB |
Execution killed with signal 9 |
14 |
Runtime error |
192 ms |
131076 KB |
Execution killed with signal 9 |
15 |
Runtime error |
193 ms |
131076 KB |
Execution killed with signal 9 |
16 |
Runtime error |
194 ms |
131076 KB |
Execution killed with signal 9 |
17 |
Runtime error |
193 ms |
131076 KB |
Execution killed with signal 9 |