Жишээ тэстүүд

Оролт
2 2 3
1 2
1 2
1 2
2 3
Гаралт
56
Оролт
5 1 4
1 2
2 5
3 4
4 2
1 2
1 3
1 4
Гаралт
151

Тэмдэглэл

Consider the first test case. There are two trees composed of two nodes, and one tree with three nodes. The maximum possible answer is obtained if the trees are connected in a single chain of 7 vertices.

In the second test case, a possible choice of new edges to obtain the maximum answer is the following:

  • Connect node 3 from the first tree to node 1 from the second tree;
  • Connect node 2 from the third tree to node 1 from the second tree.