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

View as PDF

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 vertices and some number of edges, with the vertices representing intersections, and the roads representing edges. Over days, they will be given an additional requirement, specifying that a new road is to be paved between intersections and , which requires their road paving machine to pave the road exactly 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.

#### Input Specification

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

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

#### Output Specification

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

#### Sample Input 1

2 2
1 2 2
2 1 1

#### Sample Output 1

YES
YES

#### Sample Explanation 1

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

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

#### Sample Input 2

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

#### Sample Output 2

YES
NO
YES
YES

#### Sample Explanation 2

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

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 .

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