301844: CF348E. Pilgrims
Memory Limit:256 MB
Time Limit:2 S
Judge Style:Text Compare
Creator:
Submit:0
Solved:0
Description
Pilgrims
题意翻译
很久很久以前,有一块叫做Dudeland的土地,由$n-1$条双向道路和$n$座城镇构成。从任何一个城镇出发都能到达其他所有城镇。Dudeland有$m$座城市有修道院,每座修道院里住着一名朝圣者。 年初,每座修道院的朝圣者都会列出离他所在城镇最远的修道院,如果有多个,就全部写下来。当Big Lebowski Day来临的时候,所有的朝圣者就会步行去往任意一个他列出来的修道院。 Walter讨厌朝圣者,所以他将摧毁一座没有修道院的城镇,这座城镇就无法通行了。Walter想知道,摧毁哪座城镇,可以让尽可能多的朝圣者无法到达任何一个他写下的目的地,并求出有多少朝圣者无法到达。题目描述
A long time ago there was a land called Dudeland. Dudeland consisted of $ n $ towns connected with $ n-1 $ bidirectonal roads. The towns are indexed from $ 1 $ to $ n $ and one can reach any city from any other city if he moves along the roads of the country. There are $ m $ monasteries in Dudeland located in $ m $ different towns. In each monastery lives a pilgrim. At the beginning of the year, each pilgrim writes down which monastery is the farthest from the monastery he is living in. If there is more than one farthest monastery, he lists all of them. On the Big Lebowski day each pilgrim picks one town from his paper at random and starts walking to that town. Walter hates pilgrims and wants to make as many of them unhappy as possible by preventing them from finishing their journey. He plans to destroy exactly one town that does not contain a monastery. A pilgrim becomes unhappy if all monasteries in his list become unreachable from the monastery he is living in. You need to find the maximum number of pilgrims Walter can make unhappy. Also find the number of ways he can make this maximal number of pilgrims unhappy: the number of possible towns he can destroy.输入输出格式
输入格式
The first line contains two integers $ n $ ( $ 3<=n<=10^{5} $ ) and $ m $ ( $ 2<=m<n $ ). The next line contains $ m $ distinct integers representing indices of towns that contain monasteries. Next $ n-1 $ lines contain three integers each, $ a_{i} $ , $ b_{i} $ , $ c_{i} $ , indicating that there is an edge between towns $ a_{i} $ and $ b_{i} $ of length $ c_{i} $ ( $ 1<=a_{i},b_{i}<=n,1<=c_{i}<=1000,a_{i}≠b_{i} $ ).
输出格式
Output two integers: the maximum number of pilgrims Walter can make unhappy and the number of ways in which he can make his plan come true.
输入输出样例
输入样例 #1
8 5
7 2 5 4 8
1 2 1
2 3 2
1 4 1
4 5 2
1 6 1
6 7 8
6 8 10
输出样例 #1
5 1