DMOPC '21 Contest 9 P3 - Terrible Trains

View as PDF

Submit solution


Points: 12 (partial)
Time limit: 2.0s
Memory limit: 256M

Author:
Problem type

The Terrible Trains Committee (TTC) runs a railway network consisting of N stations connected by M rail routes, each of the routes taking 1 hour to travel in either direction. The N stations are connected so that there is a sequence of routes between any two stations. Despite their terrible trains, the TTC has managed to obtain enough funding to add exactly one additional rail route to their network. This new route may be added between any two stations and will also take 1 hour to travel in either direction regardless of which stations it connects.

Upon learning this news, Q commuters have reported to the TTC headquarters with a request. The i-th of them would like for it to be possible to get from station Si to station Ti in at most Xi hours (their morning route) and from station Ui to station Vi in at most Yi hours (their evening route). As the railway designer, it is your job to tell each commuter whether it is theoretically possible for their request to be satisfied after adding the additional rail route.

Constraints

2N3×103

1M3×103

1ai,biN

1Q106

1Si,Ti,Xi,Ui,Vi,YiN

Each rail route connects two different stations.

No two of the original rail routes connect the same pair of stations.

Subtask 1 [50%]

1Q3×103

Subtask 2 [50%]

No additional constraints.

Input Specification

The first line contains 2 integers N and M.

The next M lines each contain 2 integers ai and bi, the two stations that the i-th rail route connects.

The next line contains an integer Q.

The next Q lines each contain 6 integers Si, Ti, Xi, Ui, Vi, and Yi, as described in the problem statement.

Output Specification

For each commuter, output YES if it is possible to satisfy their request or NO otherwise.

Sample Input

Copy
8 8
1 8
2 1
3 4
2 3
2 5
4 7
6 4
4 5
3
1 6 3 7 8 4
3 5 3 7 8 1
1 6 3 3 5 1

Sample Output

Copy
YES
YES
NO

Comments

There are no comments at the moment.