You are given an undirected tree with 'n' nodes, labeled 0 to n-1. Each node is represented by a value in a coins array:
1: The node contains a coin.
0: The node does not contain a coin.
You start your journey at any node you choose. To collect all the coins in the tree, you must visit every node that has a coin. Moving from a node to an adjacent node costs 1 operation.
Your task is to find the minimum total number of operations (edge traversals) required to visit all nodes containing coins. You do not need to return to your starting node.
Input Format:
The first line of input contains an integer 'n', the number of nodes.
The second line contains 'n' space-separated integers (0s and 1s), representing the coins array.
The third line contains an integer 'E', the number of edges (which will be n-1 for a tree).
The next 'E' lines each contain two space-separated integers, u and v, representing an edge.
Output Format:
Print a single integer representing the minimum number of operations required.
Note:
The key to this problem is understanding that the set of required edges to travel is fixed, regardless of the starting point. The journey must cover all edges on the unique paths between all coin-containing nodes.
The optimal path will traverse every necessary edge twice (once down, once back up), except for the longest path from the chosen starting node to a leaf in the "coin subtree", which is traversed only once.