Help required| queries based tree question

Revision en2, by loverBoUy, 2022-09-05 10:14:59

Statement: You've given a tree of N (1<=N<=1e5) nodes with the root at 1. Each node is initially healthy except the root node. You're given q (1<=q<=1e5) queries and each query is of 2 types. For each query of type 2, store the answers and return the final answer vector.

Type 1: You're given node v, make it unhealthy. Type 2: You're given node v, find the nearest unhealthy node from v. Distance is calculated as the number of edges between the current node v and the nearest unhealthy node.

Please share your optimized logic.

TIA

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en2 English loverBoUy 2022-09-05 10:14:59 2
en1 English loverBoUy 2022-09-05 10:14:40 584 Initial revision (published)