#K68362. Grid Coverage by Bus Routes
Grid Coverage by Bus Routes
Grid Coverage by Bus Routes
In this problem, you are given a grid with (N) rows and (M) columns, and (K) bus routes. Each bus route is defined by four integers (x_1, y_1, x_2, y_2) representing the starting and ending coordinates. Note that each route is guaranteed to be either horizontal (same row) or vertical (same column). A route covers all the cells along the direct path between its endpoints (inclusive). Your task is to determine if all cells of the grid are covered by at least one bus route.
For example, consider a grid with 2 rows and 2 columns and the following 4 routes:
- (1, 1, 1, 2)
- (1, 1, 2, 1)
- (1, 2, 2, 2)
- (2, 1, 2, 2)
Every cell in the grid is covered and the answer is Yes
.
The answer should be output as Yes
or No
.
inputFormat
Input is provided from standard input (stdin) in the following format:
The first line contains three integers (N), (M), and (K), representing the number of rows, columns, and bus routes respectively.
Each of the following (K) lines contains four integers (x_1), (y_1), (x_2), (y_2) representing a bus route. It is guaranteed that each route is either horizontal ((x_1 = x_2)) or vertical ((y_1 = y_2)).
outputFormat
Output a single line to standard output (stdout) containing either Yes
if every cell in the grid is covered by at least one bus route, or No
otherwise.## sample
3 3 2
1 1 1 3
1 1 3 1
No