CF1932G.Moving Platforms

提高+/省选-

通过率:0%

时间限制:3.00s

内存限制:512MB

AC君温馨提醒

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

题目描述

There is a game where you need to move through a labyrinth. The labyrinth consists of nn platforms, connected by mm passages.

Each platform is at some level lil_i, an integer number from 00 to H−1H - 1. In a single step, if you are currently on platform ii, you can stay on it, or move to another platform jj. To move to platform jj they have to be connected by the passage, and their levels have to be the same, namely li=ljl_i = l_j.

After each step, the levels of all platforms change. The new level of platform ii is calculated as li′=(li+si) mod Hl'_i = (l_i + s_i) \bmod H, for all ii.

You start on platform 11. Find the minimum number of steps you need to get to platform nn.

有一个游戏,你需要穿越一座迷宫。该迷宫由 nn 个平台组成,平台之间通过 mm 条通道相连。

每个平台位于某个层级 lil_i,其值为从 00 到 H−1H - 1 的整数。在单步操作中,若你当前位于平台 ii,你可以选择停留在该平台,或移动到另一平台 jj。要移动到平台 jj,必须满足:平台 ii 与平台 jj 之间存在一条通道,并且它们的层级相同,即 li=ljl_i = l_j。

每步操作结束后,所有平台的层级都会发生变化。平台 ii 的新层级按如下公式计算:li′=(li+si) mod Hl'_i = (l_i + s_i) \bmod H,对所有 ii 均成立。

你从平台 11 出发。求到达平台 nn 所需的最少步数。

输入格式

The first line of input contains a single integer tt (1≤t≤1041 \le t \le 10^4) — the number of test cases. Then the descriptions of the test cases follow.

The first line of each test case contains three integers nn, mm, and HH (2≤n≤1052 \le n \le 10^5, 1≤m≤1051 \le m \le 10^5, 1≤H≤1091 \le H \le 10^9).

The second line contains nn integers lil_i, the initial level of each platform (0≤li≤H−10 \le l_i \le H-1).

The third line contains nn integers sis_i, the change of level for each platform (0≤si≤H−10 \le s_i \le H-1).

Next mm lines contain a description of the passages. Each passage is described as a pair of integers — the platforms, connected by the passage. There is at most one passage connecting each pair of platforms, and there is no passage connecting a platform to itself.

The sum of nn for all tests does not exceed 10510^5, the sum of mm for all tests does not exceed 10510^5.

输入的第一行包含一个整数 tt(1≤t≤1041 \le t \le 10^4),表示测试用例的数量。随后是各测试用例的描述。

每个测试用例的第一行包含三个整数 nn、mm 和 HH(2≤n≤1052 \le n \le 10^5,1≤m≤1051 \le m \le 10^5,1≤H≤1091 \le H \le 10^9)。

第二行包含 nn 个整数 lil_i,表示每个平台的初始高度(0≤li≤H−10 \le l_i \le H-1)。

第三行包含 nn 个整数 sis_i,表示每个平台的高度变化量(0≤si≤H−10 \le s_i \le H-1)。

接下来的 mm 行描述了通道。每条通道由一对整数表示——即该通道所连接的两个平台。任意两个平台之间至多存在一条通道,且不存在连接平台到其自身的通道。

所有测试用例的 nn 之和不超过 10510^5,所有测试用例的 mm 之和不超过 10510^5。

输出格式

For each test case, print a single integer, the minimum number of steps needed to get from platform 11 to platform nn.

If it is impossible to get to platform nn, print −1-1.

对于每个测试用例,输出一个整数,表示从平台 11 到达平台 nn 所需的最少步数。

如果无法到达平台 nn,则输出 −1-1。

输入输出样例

  • 输入#1

    3
    3 3 10
    1 9 4
    2 3 0
    1 2
    3 2
    1 3
    2 1 10
    1 2
    4 6
    1 2
    8 7 25
    22 14 5 3 10 14 11 1
    9 5 4 10 7 16 18 18
    2 8
    6 3
    3 5
    7 5
    2 6
    1 4
    4 7

    输出#1

    6
    -1
    52

说明/提示

This is how levels of the platforms change, and what actions we need to perform in the first example.

Platform 1

Platform 2

Platform 3

Action

Step 1

1

9

4

Stay on the platform 1

Step 2

3

2

4

Stay on the platform 1

Step 3

5

5

4

Move to the platform 2

Step 4

7

8

4

Stay on the platform 2

Step 5

9

1

4

Stay on the platform 2

Step 6

1

4

4

Move to the platform 3

平台层级的变化方式,以及第一个示例中我们需要执行的操作如下所示:

平台 1

平台 2

平台 3

操作

第 1 步

1

9

4

停留在平台 1

第 2 步

3

2

4

停留在平台 1

第 3 步

5

5

4

移动到平台 2

第 4 步

7

8

4

停留在平台 2

第 5 步

9

1

4

停留在平台 2

第 6 步

1

4

4

移动到平台 3

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

首页