I can’t understand the test case

0 is black vertex and 1 is white vertex.

Now see the diagram carefully.

how node 1 2 3 output 2 2 2

look at the subtrees for each node and count the number of black vertices and white vertices

can you explain for node 1? how it has 2 difference

can anyone define what is a subtree?

out of nines nodes can 1 2 3 node can be a subtree?

according to wikipedia—A subtree of a tree T is a tree consisting of a node in T and all of its descendants in T…

it should include all descendants of child node

Note that there’s no root in the tree.

“The subtree of the tree is the connected subgraph of the given tree.”

So basically it’s like a spanning tree from the vertex v, such that the answer is maximum.

this is valid only for rooted nodes?

But the problem statement redefined what a subtree is, so you should use the definition in the statement and not the one on wikipedia.

okay thanks got it.