In memory of my grandfather.
My grandfather is an experienced forester; he knows every glade (there are a total of N in the forest), every path between certain pairs of glades, which can only be walked in one direction (there are M paths), as well as how many mushrooms and berries grow on each path on any given day.
My grandfather is a creature of habit, and as he told me, he got used to going to the forest every day, starting from glade number 1 and ending at glade number N. Naturally, the paths in the forest are arranged in such a way that, by following them sequentially, one can never get lost, meaning he will never end up on a glade he has already visited.
My grandfather went to the forest on each of the Q days of summer, and during this season, there is a market at each glade where mushrooms and berries can be sold. On the i-th day, mushrooms can be sold for ai rubles each at any glade, and berries for bi rubles each. My grandfather mentioned that every day, while passing each path, he immediately sold all the mushrooms and berries he collected on it at the corresponding market at the current rate, and he always earned more from mushrooms than from berries.
My grandfather is fond of exaggerating his achievements, so I need your help. Determine for each day whether it is true that my grandfather was able to walk from glade 1 to glade N and earn more from mushrooms than from berries after passing each path. Note that on different days, my grandfather could choose different routes.
Input
The first line contains three integers N, M, and Q—the number of glades and paths in the forest and the number of summer days (2 ≤ N ≤ 105, 1 ≤ M, Q ≤ 105).
The next M lines describe the paths with four integers ui, vi, si, and wi—the numbers of the glades from which and to which the path leads, and the number of mushrooms and berries on this path on any day (1 ≤ ui, vi ≤ 105, ui ≠q vi, 1 ≤ si, wi ≤ 109).
The next Q lines contain two integers aj and bj—the price of one mushroom and one berry on the j-th day (1 ≤ aj, bj ≤ 109).
It is guaranteed that two different paths cannot connect the same pair of glades, and they do not form a cycle.
Output
Output Q lines. In the i-th line, output “YES” if on the i-th day my grandfather was able to walk as he described, or “NO” otherwise.
Sample
input | output |
---|
3 3 3
1 2 2 4
2 3 3 9
1 3 10 50
58 9
60 23
61 9
| YES
NO
YES
|
Problem Author: Vadim Barinov
Problem Source: Ural Regional Contest Qualifier 2022