WOSS Dual Olympiad 2023 S3: Flying
View as PDFManasva "JARVIS" Katyal is going on an adventure in his beloved Grob 120A. There are  destinations connected by 
 routes. The 
th route connects destination 
 with destination 
, using up 
 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 
 questions. For each question, he asks if it would be possible to fly from destination 
 to 
 while using exactly 
 units of fuel.
Constraints
Subtask 1 [40%]
Subtask 2 [60%]
Input Specification
The first line contains  space-separated integers, 
 and 
.
The next  lines each contain 
 space-separated integers, 
, 
, and 
, indicating a route connecting destination 
 with destination 
 which uses 
 units of fuel.
The next  lines each contain 
 space-separated integers, 
 and 
.
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
5 4
2 1 9
1 4 4
2 5 11
3 1 6
3 24
1 17
3 21
2 47
Sample Output
YES
NO
NO
YES
Comments