The XYZ Corporation has found 5 rare minerals, which are located on different regions of several islands along the East Coast of the Pacific. The company believes that it would be a best opportunity to gain profits. However, due to the financial crisis, the company does not have enough manpower or money spending in building orefields on all the islands. Therefore, the Committee has chosen some islands that have relatively higher ore storages, and sent one investigator to each of these islands to make a survey of the ore distribution on the island. The survey results show that each island has many villages which are connected with paths. Because of the time consuming, the investigator does not record all the paths on his map. Instead, according to his map, there is one and only one way to go from one village to another(map is drawn like a tree).
The company plans to establish a sub-plant on one of the villages in each of the chosen islands. All the 5 rare minerals dug from different locations of that island will be sent to this sub-plant, and after being made into a kind of compound metal. To minimize the cost on building transportation road, the company decides to broaden the original paths rather than constructing new roads. Moreover, the company determines to build the orefields in the villages to make sure they can hire enough workers. (If the sub-plant is located in one village, the orefields can also be built in that village.)
Since the ore storages in these islands are very high, each kind of rare minerals only needs one orefield. Now given the maps of the chosen islands, you need to find the most appropriate village as the sub-plant on each island, and broaden a shortest length of paths to meet the needs of all the 5 rare minerals.