#C3799. Robo Walker: Valid Checkpoint Path
Robo Walker: Valid Checkpoint Path
Robo Walker: Valid Checkpoint Path
You are given a grid of size n × m and p checkpoints, each specified by its row and column coordinates. The task is to determine whether there exists a valid path that visits each checkpoint exactly once. A valid path is defined as one that traverses all checkpoints without revisiting any of them. In other words, if all the provided checkpoints are distinct, a valid path exists. This can be formally stated by the condition:
\( |\{(x_i, y_i)\}_{i=1}^{p}| = p \)
If the above condition holds, output YES; otherwise, output NO.
inputFormat
The input begins with an integer T (the number of test cases). Each test case is formatted as follows:
- The first line contains three space-separated integers: n (number of rows), m (number of columns), and p (number of checkpoints).
- This is followed by p lines, each containing two space-separated integers that represent the row and column indices of a checkpoint.
outputFormat
For each test case, output a single line containing either YES if a valid path exists (i.e. all checkpoints are unique) or NO if any checkpoint is repeated.
## sample5
4 4 2
0 1
2 3
4 4 3
0 1
2 3
0 0
2 2 2
0 0
1 1
3 3 4
0 0
1 1
0 0
2 2
3 3 9
0 0
0 1
0 2
1 0
1 1
1 2
2 0
2 1
2 2
YES
YES
YES
NO
YES
</p>