QOJ.ac

QOJ

Limite de temps : 3.0 s Limite de mémoire : 256 MB Points totaux : 100

#11610. 超越救援

Statistiques

Riatla 是刺客组织的一名无名成员(如你所知,著名的刺客通常活不长)。在执行完一次任务后,Riatla 面临一个问题:城市的街道被守卫淹没了,他需要从犯罪现场制定一个新的逃生计划。

Riatla 目前所在的城市具有树状结构。城市中有 $n$ 个广场,由 $n-1$ 条双向街道连接,任意两个广场之间只有一条路径。

Riatla 的同伙发现守卫正沿着一条循环路线巡逻:他们选择了一个广场序列 $v_1, v_2, \dots, v_k$,在访问完广场 $v_i$ 后,守卫会前往广场 $v_{i+1}$(它们之间可能没有直接相连的街道,此时守卫会沿着它们之间的最短路径行进)。在访问完 $v_k$ 后,他们会前往 $v_1$,并从头开始他们的路线。

Riatla 擅长伪装。城市里的所有广场都很拥挤,因此即使守卫也在同一个广场上,刺客也可以待在广场里而不必担心被发现。另一方面,街道上的人并不多,所以如果刺客和守卫在任何时刻同时出现在同一条街道上,无论距离多远,守卫都会用弓箭射杀刺客。

你知道城市的规划以及守卫和刺客通过每条街道所需的时间。你需要计算 Riatla 从他现在所在的广场 $s$ 到他的朋友们正在等他的广场 $t$ 所需的最短时间。由于这个时间可能非常长,你只需要计算其对 $998\,244\,353$ 取模后的结果。

输入格式

输入的第一行包含一个整数 $t$:测试用例的数量。接下来是 $t$ 个测试用例。

每个测试用例的第一行包含两个整数 $n$ 和 $k$:城市中的广场数量以及守卫路径上的重要广场数量($2 \le n, k \le 200\,000$)。

接下来的 $n-1$ 行,每行包含四个整数 $u_i, v_i, c_i$ 和 $d_i$:表示由街道连接的广场,以及守卫和刺客通过每条街道所需的时间($1 \le u_i, v_i \le n$;$1 \le c_i, d_i \le 10^8$)。保证给定的图是一棵树。

下一行包含 $k$ 个整数 $a_i$:守卫路径上重要广场的索引,按守卫访问它们的顺序排列($1 \le a_i \le n$;$a_i \neq a_{i+1}$;$a_1 \neq a_k$)。

下一行包含两个整数 $s$ 和 $t$:刺客的起始广场和路径的终点广场($1 \le s, t \le n$;$s \neq t$)。

保证所有测试用例中 $n$ 的总和与 $k$ 的总和均不超过 $200\,000$。

输出格式

对于每个测试用例,在单独的一行中打印一个数字:刺客所需的最短时间,对 $998\,244\,353$ 取模。

如果刺客无法在不被发现的情况下到达目标,则打印 $-1$。

样例

输入 1

2
5 4
1 2 1 4
2 3 1 4
3 4 1 4
4 5 10 10
1 4 1 5
1 4
2 2
1 2 2 1
1 2
1 2

输出 1

16
-1

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.