Wesley's Anger Contest 3 Problem 4 - Canadian Construction Crew

View as PDF

Submit solution


Points: 12 (partial)
Time limit: 1.0s
Python 3.0s
Memory limit: 256M

Author:
Problem type

The Canadian Construction Crew (CCC) is working on a new project! They have been tasked with paving the roads in a city. The road network can be modelled by a graph with N vertices and some number of edges, with the vertices representing intersections, and the roads representing edges. Over Q days, they will be given an additional requirement, specifying that a new road is to be paved between intersections ai and bi, which requires their road paving machine to pave the road exactly xi times, no more, no less. Unfortunately, their road paving machine does not have an off switch and will pave every road that it travels on. The road paving machine must start and end at any intersection (possibly two different intersections) and cannot be moved to a different intersection without paving the roads in between the intersections. The road paving machine may decide to move back and forth on the same road until it is paved exactly the correct number of times. After each day, can you determine if there is a way to satisfy each of the requirements up to and including that day? Note that the road paving machine does not actually pave the roads at the end of each day. You are simply tasked with determining whether it is possible to pave the roads.

There may be multiple roads between two intersections, but there will not be a road between an intersection and itself.

Constraints

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

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

For all subtasks:

2N100000
1Q300000
1ai,biN
aibi
1xi1000

Subtask 1 [10%]

2N3
1Q3

Subtask 2 [40%]

2N1000
1Q3000

Subtask 3 [50%]

No additional constraints.

Input Specification

The first line of input contains 2 integers, N and Q, representing the number of intersections in the city, and the number of days where requirements will be given.

The next Q lines describe the requirements. Each line contains 3 integers, ai, bi, xi, indicating that on the ith day, a new road is required to be paved exactly xi times between intersections ai, and bi.

Output Specification

Output Q lines. On the ith line, output YES if it is possible to use the road paver machine to satisfy all requirements up to and including the ith day. Otherwise, output NO.

Sample Input 1

Copy
2 2
1 2 2
2 1 1

Sample Output 1

Copy
YES
YES

Sample Explanation 1

On the first day, the road paving machine can take the path 121.

On the second day, the road paving machine can take the path 2121.

Sample Input 2

Copy
4 4
1 2 1
4 3 2
4 2 1
2 3 2

Sample Output 2

Copy
YES
NO
YES
YES

Sample Explanation 2

On the first day, the road paving machine can take the path 12.

On the second day, the road paving machine cannot take any path to pave both roads.

On the third day, the road paving machine can take the path 12434.

On the fourth day, the road paving machine can take the path 1234234.


Comments

There are no comments at the moment.