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 <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;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |