CF348E.Pilgrims

省选/NOI-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

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.

很久以前,有一片名为“杜德兰”(Dudeland)的土地。杜德兰由 nn 座城镇组成,这些城镇通过 n−1n-1 条双向道路相连。城镇编号为 11 到 nn,且任意两座城镇之间均可通过道路相互到达(即该图是一棵树)。杜德兰共有 mm 座修道院,分别位于 mm 个互不相同的城镇中;每座修道院中住着一位朝圣者。

每年年初,每位朝圣者都会写下距离自己所居住的修道院最远的修道院。若存在多个最远的修道院,则全部列出。在“大勒博夫斯基日”(Big Lebowski day),每位朝圣者会从自己写下的列表中随机选择一个城镇,并开始向该城镇进发。

沃尔特(Walter)憎恨朝圣者,他希望通过阻止尽可能多的朝圣者完成旅程,使他们变得不开心。他计划恰好摧毁一座不包含修道院的城镇。当某位朝圣者所列的所有修道院,均无法再从他所居住的修道院经剩余道路到达时,这位朝圣者即变得不开心。

你需要求出:沃尔特最多能使多少位朝圣者不开心?此外,还需算出他能达成这一最大不开心人数的方案数——即他可选择摧毁的、满足条件的城镇个数。

输入格式

The first line contains two integers n (3 ≤ n ≤ 105) 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).

第一行包含两个整数 nn(3 ≤ n ≤ 1053 \leq n \leq 10^5)和 mm(2 ≤ m < n2 \leq m < n)。下一行包含 mm 个互不相同的整数,表示含有寺院的城镇编号。

接下来的 n − 1n - 1 行每行包含三个整数 aia_i、bib_i、cic_i,表示城镇 aia_i 与城镇 bib_i 之间存在一条长度为 cic_i 的边(1 ≤ ai, bi ≤ n1 \leq a_i,\,b_i \leq n,1 ≤ ci ≤ 10001 \leq c_i \leq 1000,ai ≠ bia_i \neq 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.

输出两个整数:Walter 能够使不开心的朝圣者数量的最大值,以及他实现该计划的方案数。

输入输出样例

  • 输入#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

输入解题思路,AI测评打分。不知道怎么写?

首页