QOJ.ac

QOJ

时间限制: 2.0 s 内存限制: 1024 MB 总分: 100 可 Hack ✓

#9298. 相遇

统计

威海位于山东半岛最东端,是中国最著名的旅游目的地之一。威海拥有美丽的山丘、海洋、海湾、泉水、岛屿和美丽的沙滩。它也是一座盛产海鲜的沿海城市,包括对虾、海参、鲍鱼、贝类和藻类。

受其独特的风景和宜人的环境吸引,三位理论计算机科学家计划去威海旅游。然而,他们在住宿问题上无法达成共识,因为有些人喜欢某些酒店,而另一些人则喜欢其他的。他们决定晚上可能住在不同的酒店,并在第二天在某一家酒店会合。他们会合的酒店不一定是他们住宿的酒店。

威海的酒店之间有一些道路相连。这些道路经过特殊设计,使得任意两家酒店之间都存在唯一的路径。每位理论计算机科学家在旅行开始前都准备了一份候选酒店名单。当他们到达威海时,每个人都会从各自的候选酒店名单中均匀且独立地选择一家酒店。此外,他们会在一家酒店会合,使得他们路线的总长度最小化。作为理论计算机科学小组的一员,你能告诉他们路线总长度的期望值吗?

输入格式

第一行包含一个整数 $n$ ($1 \le n \le 200\,000$),表示威海的酒店数量。接下来 $n-1$ 行,描述连接酒店的道路。每行包含三个整数 $u, v, w$ ($1 \le u, v \le n, u \neq v, 1 \le w \le 1000$),表示一条连接编号为 $u$ 和 $v$ 的酒店、长度为 $w$ 的道路。保证任意两家酒店之间存在唯一的路径。

最后三行描述每位理论计算机科学家的候选酒店名单。每行以一个整数 $m$ ($1 \le m \le n$) 开头,后跟 $m$ 个不同的整数 $a_1, a_2, \dots, a_m$ ($1 \le a_i \le n$),表示候选酒店名单包含编号为 $a_1, a_2, \dots, a_m$ 的酒店。

输出格式

输出路线总长度的期望值,要求绝对误差或相对误差不超过 $10^{-6}$。

样例

样例输入 1

3
1 2 1
2 3 2
1 1
1 2
1 3

样例输出 1

3

样例输入 2

5
1 2 3
1 3 5
2 4 7
2 5 11
3 2 4 5
4 1 2 3 5
2 1 3

样例输出 2

13.958333333333

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.