CF1515G.Phoenix and Odometers

普及/提高-

通过率:0%

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.

输入格式

The first line of the input contains two integers nn and mm ( 2n21052 \le n \le 2 \cdot 10^5 ; 1m21051 \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 ( 1ai,bin1 \le a_i, b_i \le n ; aibia_i \neq b_i ; 1li1091 \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 ( 1q21051 \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 ( 1vin1 \le v_i \le n ; 0si<ti1090 \le s_i < 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.

输出格式

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.

输入输出样例

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

首页