WOSS Dual Olympiad 2023 S3: Flying

View as PDF

Submit solution


Points: 15 (partial)
Time limit: 5.0s
Memory limit: 1G

Authors:
Problem type

Manasva "JARVIS" Katyal is going on an adventure in his beloved Grob 120A. There are N destinations connected by N1 routes. The ith route connects destination ui with destination vi, using up li units of fuel. Routes can be flown both ways and multiple times. It is possible to reach every destination from every other destination using these routes. Since Manasva spent his life savings buying the Grob 120A, he's being really frugal and wants to save fuel. He asks Q questions. For each question, he asks if it would be possible to fly from destination 1 to qi while using exactly ci units of fuel.

Constraints

1N103

1Q106

1ui,vi,qiN

1li103

Subtask 1 [40%]

1ci103

Subtask 2 [60%]

1ci109

Input Specification

The first line contains 2 space-separated integers, N and Q.

The next N1 lines each contain 3 space-separated integers, ui, vi, and li, indicating a route connecting destination ui with destination vi which uses li units of fuel.

The next Q lines each contain 2 space-separated integers, qi and ci.

Output Specification

For each query, output a single line containing YES if there exists a path and NO if there is no valid path.

Sample Input

Copy
5 4
2 1 9
1 4 4
2 5 11
3 1 6
3 24
1 17
3 21
2 47

Sample Output

Copy
YES
NO
NO
YES

Comments

There are no comments at the moment.