Help required| queries based tree question

Правка en2, от 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

История

 
 
 
 
Правки
 
 
  Rev. Язык Кто Когда Δ Комментарий
en2 Английский loverBoUy 2022-09-05 10:14:59 2
en1 Английский loverBoUy 2022-09-05 10:14:40 584 Initial revision (published)