CF1515G.Phoenix and Odometers

省选/NOI-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

In Fire City, there are nn intersections and mm one-way roads. The ii-th road goes from intersection aia_i to bib_i and has length lil_i miles.

There are qq cars that may only drive along those roads. The ii-th car starts at intersection viv_i and has an odometer that begins at sis_i, increments for each mile driven, and resets to 00 whenever it reaches tit_i. Phoenix has been tasked to drive cars along some roads (possibly none) and return them to their initial intersection with the odometer showing 00.

For each car, please find if this is possible.

A car may visit the same road or intersection an arbitrary number of times. The odometers don't stop counting the distance after resetting, so odometers may also be reset an arbitrary number of times.

在火焰城中有 nn 个路口和 mm 条单向道路。第 ii 条道路从路口 aia_i 指向 bib_i,长度为 lil_i 英里。

共有 qq 辆汽车,它们只能沿这些道路行驶。第 ii 辆汽车从路口 viv_i 出发,其里程表初始读数为 sis_i,每行驶一英里便加 11,当读数达到 tit_i 时自动重置为 00。凤凰的任务是驾驶每辆汽车沿若干道路(可以不经过任何道路)行驶,并最终使其返回出发路口,且此时里程表读数恰好为 00。

对每辆汽车,请判断该任务是否可行。

一辆汽车可任意多次经过同一条道路或同一个路口。里程表在重置后不会停止计数,因此里程表也可被重置任意多次。

输入格式

The first line of the input contains two integers nn and mm (2≤n≤2⋅1052 \le n \le 2 \cdot 10^5; 1≤m≤2⋅1051 \le m \le 2 \cdot 10^5) — the number of intersections and the number of roads, respectively.

Each of the next mm lines contain three integers aia_i, bib_i, and lil_i (1≤ai,bi≤n1 \le a_i, b_i \le n; ai≠bia_i \neq b_i; 1≤li≤1091 \le l_i \le 10^9) — the information about the ii-th road. The graph is not necessarily connected. It is guaranteed that between any two intersections, there is at most one road for each direction.

The next line contains an integer qq (1≤q≤2⋅1051 \le q \le 2 \cdot 10^5) — the number of cars.

Each of the next qq lines contains three integers viv_i, sis_i, and tit_i (1≤vi≤n1 \le v_i \le n; 0≤si<ti≤1090 \le s_i \lt t_i \le 10^9) — the initial intersection of the ii-th car, the initial number on the ii-th odometer, and the number at which the ii-th odometer resets, respectively.

输入的第一行包含两个整数 nn 和 mm(2≤n≤2⋅1052 \le n \le 2 \cdot 10^5;1≤m≤2⋅1051 \le m \le 2 \cdot 10^5),分别表示交叉路口的数量和道路的数量。

接下来的 mm 行,每行包含三个整数 aia_i、bib_i 和 lil_i(1≤ai,bi≤n1 \le a_i, b_i \le n;ai≠bia_i \neq b_i;1≤li≤1091 \le l_i \le 10^9),描述第 ii 条道路的信息。该图不一定连通。保证任意两个交叉路口之间,每个方向至多存在一条道路。

下一行包含一个整数 qq(1≤q≤2⋅1051 \le q \le 2 \cdot 10^5),表示汽车的数量。

接下来的 qq 行,每行包含三个整数 viv_i、sis_i 和 tit_i(1≤vi≤n1 \le v_i \le n;0≤si<ti≤1090 \le s_i \lt t_i \le 10^9),分别表示第 ii 辆汽车的初始交叉路口、初始里程表读数以及里程表重置时的数值。

输出格式

Print qq answers. If the ii-th car's odometer may be reset to 00 by driving through some roads (possibly none) and returning to its starting intersection viv_i, print YES. Otherwise, print NO.

输出 qq 个答案。如果第 ii 辆车的里程表可以通过驶过若干条道路(可以为零条)并返回其起始交叉路口 viv_i 而被重置为 00,则输出 YES;否则输出 NO。

输入输出样例

  • 输入#1

    4 4
    1 2 1
    2 3 1
    3 1 2
    1 4 3
    3
    1 1 3
    1 2 4
    4 0 1

    输出#1

    YES
    NO
    YES
  • 输入#2

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

    输出#2

    YES
    YES

说明/提示

The illustration for the first example is below:

In the first query, Phoenix can drive through the following cities: 11 →\rightarrow 22 →\rightarrow 33 →\rightarrow 11 →\rightarrow 22 →\rightarrow 33 →\rightarrow 11. The odometer will have reset 33 times, but it displays 00 at the end.

In the second query, we can show that there is no way to reset the odometer to 00 and return to intersection 11.

In the third query, the odometer already displays 00, so there is no need to drive through any roads.

Below is the illustration for the second example:

第一个示例的示意图如下:

在第一次查询中,凤凰可以依次经过以下城市:11 →\rightarrow 22 →\rightarrow 33 →\rightarrow 11 →\rightarrow 22 →\rightarrow 33 →\rightarrow 11。里程表将重置 33 次,但最终显示值为 00。

在第二次查询中,可以证明不存在一种方式,使得里程表重置为 00 并同时返回到交叉路口 11。

在第三次查询中,里程表当前已显示 00,因此无需经过任何道路。

第二个示例的示意图如下:

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

首页