CF1515G.Phoenix and Odometers
普及/提高-
通过率:0%
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
In Fire City, there are n intersections and m one-way roads. The i -th road goes from intersection ai to bi and has length li miles.
There are q cars that may only drive along those roads. The i -th car starts at intersection vi and has an odometer that begins at si , increments for each mile driven, and resets to 0 whenever it reaches ti . Phoenix has been tasked to drive cars along some roads (possibly none) and return them to their initial intersection with the odometer showing 0 .
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 n and m ( 2≤n≤2⋅105 ; 1≤m≤2⋅105 ) — the number of intersections and the number of roads, respectively.
Each of the next m lines contain three integers ai , bi , and li ( 1≤ai,bi≤n ; ai=bi ; 1≤li≤109 ) — the information about the i -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 q ( 1≤q≤2⋅105 ) — the number of cars.
Each of the next q lines contains three integers vi , si , and ti ( 1≤vi≤n ; 0≤si<ti≤109 ) — the initial intersection of the i -th car, the initial number on the i -th odometer, and the number at which the i -th odometer resets, respectively.
输出格式
Print q answers. If the i -th car's odometer may be reset to 0 by driving through some roads (possibly none) and returning to its starting intersection vi , 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: 1 → 2 → 3 → 1 → 2 → 3 → 1 . The odometer will have reset 3 times, but it displays 0 at the end.
In the second query, we can show that there is no way to reset the odometer to 0 and return to intersection 1 .
In the third query, the odometer already displays 0 , so there is no need to drive through any roads.
Below is the illustration for the second example: