3475.Pilgrims

Time Limit: 1s Memory Limit: 256MB

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.

Input Format(From the terminal/stdin)

The first line contains two integers n (3 \le n \le 105) and m (2 \le m \lt n). The next line contains m distinct integers representing indices of towns that contain monasteries.

Next n-1 lines contain three integers each, ai, bi, ci, indicating that there is an edge between towns ai and bi of length ci (1 \le ai,bi \le n,1 \le ci \le 1000,ai \neq bi).

Output Format(To the terminal/stdout)

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.

Sample Input

Copy
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
 · \n
 · · · · \n
 · · \n
 · · \n
 · · \n
 · · \n
 · · \n
 · · \n
 · ·  \n

Sample Output

Copy
5 1
 · \n

Submit

请先 登录

© 2025 FAQs