#include <bits/stdc++.h>
using namespace std;
template<typename T> inline void read(T &x){
x = 0; char ch;
while(!isdigit(ch=getchar()));
do{x=10*x+ch-'0';}while(isdigit(ch=getchar()));
}
const int N = 2001;
const int M = 5e5+1;
int n, m, ra, rb;
bitset<M> Da[N], Db[N], cur;
vector<int> Ga[N], Gb[N];
void DFSa(int u){
for(int i = 0; i < (int)Ga[u].size(); i++){
int v = Ga[u][i];
Da[v] |= Da[u];
DFSa(v);
}
}
void DFSb(int u){
for(int i = 0; i < (int)Gb[u].size(); i++){
int v = Gb[u][i];
Db[v] |= Db[u];
DFSb(v);
}
}
int main()
{
ios_base::sync_with_stdio(0); cin.tie(0);
read(n); read(m);
for(int i = 1; i <= n; i++){
int x;
read(x);
if(x==0) ra = i;
else Ga[x].push_back(i);
read(x);
if(x==0) rb = i;
else Gb[x].push_back(i);
}
for(int i = 0; i < m; i++){
int x;
read(x);
Da[x].set(i);
read(x);
Db[x].set(i);
}
DFSa(ra);
DFSb(rb);
for(int i = 1; i <= n; i++){
cur = Da[i]&Db[i];
cout<<cur.count()<<'\n';
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
19 ms |
246608 KB |
Output is correct |
2 |
Correct |
13 ms |
246608 KB |
Output is correct |
3 |
Correct |
16 ms |
246608 KB |
Output is correct |
4 |
Correct |
16 ms |
246608 KB |
Output is correct |
5 |
Correct |
16 ms |
246608 KB |
Output is correct |
6 |
Correct |
19 ms |
246608 KB |
Output is correct |
7 |
Correct |
16 ms |
246608 KB |
Output is correct |
8 |
Correct |
23 ms |
246608 KB |
Output is correct |
9 |
Correct |
0 ms |
246608 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
203 ms |
246768 KB |
Output is correct |
2 |
Runtime error |
156 ms |
246768 KB |
Execution killed because of forbidden syscall writev (20) |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
346 ms |
246768 KB |
Execution killed because of forbidden syscall writev (20) |
2 |
Halted |
0 ms |
0 KB |
- |