For the sample test, one valid tree
T=(V,E) and choices of
S1,S2 corresponding to the input, is given as
E={(1,2),(2,3),(3,4),(2,5),(2,6)},
S1={(1,2),(2,3),(3,4)} and
S2={(2,3),(2,5),(2,6)}, as shown in the following graphs, where red edges represent edges in
S1 and
S2, and blue edges represent edges in
E∖S1 and
E∖S2, respectively.
For vertex
1, one optimal way is to keep
S1 and
E∖S2, leading to an intersection set
{1,2} of size
2.
For vertex
2, one optimal way is to keep
E∖S1 and
S2, leading to an intersection set
{2,5,6} of size
3.
For vertex
3, one optimal way is to keep
S1 and
S2, leading to an intersection set
{2,3} of size
2.
For vertex
4, one optimal way is to keep
S1 and
E∖S2, leading to an intersection set
{2,3} of size
2.
For vertex
5, one optimal way is to keep
E∖S1 and
S2, leading to an intersection set
{2,5,6} of size
3.
For vertex
6, one optimal way is to keep
E∖S1 and
S2, leading to an intersection set
{2,5,6} of size
3.