I have some doubts in the first dfs function that is called to root the tree at ‘a’ and to mark nodes having special node in their subtree :

EDIT : This is the same code used in the video editorial available on the official codechef channel

```
public int dfs(int v , int depth , int parent, boolean isSpec[] , int par[] , int dep[] , int ans[] , int node[],ArrayList<Integer> graph[]){
dep[v] = depth;
par[v] = parent;
int sp = -1;
for(int u : graph[v]){
if(u!=parent[v]){
int temp = dfs(u,depth+1,v,isSpec,par,dep,ans,node,graph);
if(temp!=-1&&sp==-1) sp = temp; // why are we not reassigning sp to temp when sp is not -1 , why cant we use - if(temp!=-1) sp = temp here
}
}
if(isSpec[v]) sp = v; // when we dont have a special node in subtree , then it makes sense to assign sp to v if v is a special node , but if we do have a special node in subtree then why are we reassigning sp to v if v is a special node ?
if(sp!=-1){
ans[v]= dep[v];
node[v] = sp;
}
return sp;
}
```