Wesley's Anger Contest 4 Problem 7 - Squirrel Cities

View as PDF

Submit solution


Points: 25 (partial)
Time limit: 3.0s
Java 5.0s
Python 5.0s
Memory limit: 256M

Author:
Problem types

The squirrel nation is preparing to establish an advanced highway system to connect their cities. They are scattered among N different cities and would like to build a highway network such that there is a path between any two cities. There are M different potential highway plans that they are considering. The ith highway plan connects cities ai and bi, with a bidirectional highway that has a durability of di, and takes ti time to complete.

Each highway in the network must have a minimum durability, and a maximum amount of time to completion. Since the squirrels are indecisive, they will ask you Q questions. Each question is in the form of two integers, xj, and yj. They want you to determine whether it is possible to build a highway network such that there is a path between any two cities, with each highway in the network having a durability of at least xj, and each highway taking no longer than yj time to complete.

For this problem, Python users are recommended to use PyPy over CPython.

Constraints

For this problem, you will be required to pass all the samples in order to receive points. In addition, you must pass all previous subtasks to earn points for a specific subtask.

For all subtasks:

2N100000
1M300000
1Q300000
1ai,biN for all 1iM
1di,ti109 for all 1iM
1xj,yj109 for all 1jQ

Subtask 1 [9%]

2N1000
1M3000
1Q3000

Subtask 2 [40%]

2N3000
1M9000

Subtask 3 [51%]

No additional constraints.

Input Specification

The first line of input contains 3 integers, N, M, and Q, representing the number of cities in the squirrel nation, the number of potential highway plans, and the number of questions they will ask you.

The next M lines describe the highway plans. The ith line contains 4 integers, ai, bi, di, ti, indicating that the ith plan connects cities ai and bi with a bidirectional highway that has a durability of di, and takes ti time to complete.

The next Q lines describe the questions the squirrels will ask. The jth line contains 2 integers, xj, yj, indicating that the jth question is asking whether it is possible to build a highway network such that there is a path between any two cities, with each highway in the network having a durability of at least xj, and each highway taking no longer that yj time to complete.

Output Specification

This problem is graded with an identical checker. This includes whitespace characters. Ensure that every line of output is terminated with a \n character and that there are no trailing spaces.

Output Q lines. The jth line should contain the answer to the jth query. If there is a way to build a highway network such that there is a path between any two cities, with each highway in the network having a durability of at least xj, and each highway taking no longer than yj time to complete, then output YES. Otherwise, output NO.

Sample Input 1

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

Sample Output 1

Copy
YES
NO

Sample Explanation 1

For the first question, the first and second highway plans can be built to satisfy the requirements.

For the second question, there is no possible way to build a highway network that satisfies all requirements.


Comments

There are no comments at the moment.