I want to calculate Subtree size (for each vertex ) , of a given graph I know how to do with DFS but how can i implement using BFS ?

**https://codeforces.com/blog/entry/70823?locale=en**

I also visit this above link , but unable to implement , I wanna do something with parent but how ? Please help @galencolin @carre @waqar_ahmad224 @hetp111

```
// DFS implementation
lli SubtreeSize_DFS(lli source , vi adj[] , bool* vis , lli* subtree_size){
vis[source] = 1;
lli crsize = 1;
for(auto xt : adj[source]){
if(!vis[xt])
crsize += SubtreeSize_DFS(xt,adj,vis,subtree_size);
}
subtree_size[source] = crsize;
return crsize;
}
```

```
//BFS implementataion (complete this )
void SubtreeSize_BFS(bool vis[], lli dist[], lli parent[] , lli s , lli* subtree_size){
queue<lli>q;
q.push(s);
vis[s]=1;
dist[s]=0;
parent[s] = s;
lli cnt=0;
while(q.empty()==false){
lli x = q.front();
q.pop();
for(auto xt : adj[x])
{
if(!vis[xt])
{
dist[xt] = dist[x]+1;
vis[xt]=1;
q.push(xt);
parent[xt] = x;
}
}
}
}
```