How to handle updates in DSU on trees

Revision en2, by huzaifa242, 2019-05-28 13:52:08

I read your this Blog on DSU on trees.

Now, I have a doubt.

Given a tree with n nodes and each node has some color c[i], following query needs to be answered

1 x y: change color of node x to y

2 u c: count all the nodes with color c in subtree of u.

How to approach this??

Thanks for help in advance.

Tags dsu, trees

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en3 English huzaifa242 2019-05-28 13:55:29 5 Tiny change: 'I read your [this Blo' -> 'I read [this Blo'
en2 English huzaifa242 2019-05-28 13:52:08 2 Tiny change: 'e x to y\n2 u c: c' -> 'e x to y\n\n2 u c: c'
en1 English huzaifa242 2019-05-28 13:38:42 397 Initial revision (published)