#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.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(vacio[j]=0){
vacio[j]=1;
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;
}
Compilation message
regions.cpp: In function 'int main()':
regions.cpp:46:15: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
46 | if(vacio[j]=0){
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
200 KB |
Output isn't correct |
2 |
Incorrect |
1 ms |
200 KB |
Output isn't correct |
3 |
Incorrect |
2 ms |
200 KB |
Output isn't correct |
4 |
Incorrect |
6 ms |
200 KB |
Output isn't correct |
5 |
Incorrect |
8 ms |
328 KB |
Output isn't correct |
6 |
Incorrect |
18 ms |
584 KB |
Output isn't correct |
7 |
Incorrect |
26 ms |
456 KB |
Output isn't correct |
8 |
Incorrect |
34 ms |
456 KB |
Output isn't correct |
9 |
Incorrect |
25 ms |
840 KB |
Output isn't correct |
10 |
Incorrect |
69 ms |
1480 KB |
Output isn't correct |
11 |
Incorrect |
55 ms |
1348 KB |
Output isn't correct |
12 |
Incorrect |
121 ms |
2176 KB |
Output isn't correct |
13 |
Incorrect |
154 ms |
1736 KB |
Output isn't correct |
14 |
Incorrect |
149 ms |
1996 KB |
Output isn't correct |
15 |
Incorrect |
187 ms |
2988 KB |
Output isn't correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
701 ms |
4748 KB |
Output isn't correct |
2 |
Incorrect |
880 ms |
4240 KB |
Output isn't correct |
3 |
Incorrect |
1234 ms |
5836 KB |
Output isn't correct |
4 |
Incorrect |
272 ms |
64576 KB |
Output isn't correct |
5 |
Incorrect |
399 ms |
100524 KB |
Output isn't correct |
6 |
Runtime error |
99 ms |
131076 KB |
Execution killed with signal 9 |
7 |
Runtime error |
109 ms |
131076 KB |
Execution killed with signal 9 |
8 |
Runtime error |
123 ms |
131076 KB |
Execution killed with signal 9 |
9 |
Runtime error |
152 ms |
131076 KB |
Execution killed with signal 9 |
10 |
Runtime error |
166 ms |
131076 KB |
Execution killed with signal 9 |
11 |
Runtime error |
198 ms |
131076 KB |
Execution killed with signal 9 |
12 |
Runtime error |
183 ms |
131076 KB |
Execution killed with signal 9 |
13 |
Runtime error |
183 ms |
131076 KB |
Execution killed with signal 9 |
14 |
Runtime error |
190 ms |
131076 KB |
Execution killed with signal 9 |
15 |
Runtime error |
194 ms |
131076 KB |
Execution killed with signal 9 |
16 |
Runtime error |
195 ms |
131076 KB |
Execution killed with signal 9 |
17 |
Runtime error |
218 ms |
131076 KB |
Execution killed with signal 9 |