TLE '17 Contest 1 P5 - Cake

View as PDF

Submit solution


Points: 15 (partial)
Time limit: 0.75s
Memory limit: 256M

Author:
Problem types
Flaco thinks that this cake design is too basic.

Fax McClad, Croneria's most friendly bounty hunter, has been busy preparing for his wingmate Flaco Lombradi's birthday! Fax will give him a very large cake. This is an unusual cake, so certain conditions must be met.

The cake can be divided into an R by C grid where every cell is either empty or contains cake. Rows are labelled from 1 to R, and columns are labelled from 1 to C. Every row and column has cake in it.

Also, the entire cake must be connected. In other words, it is possible to visit the entire cake by moving only up, down, left, or right, and not entering any empty cell.

Since this is Flaco's cake, he suggests a specific cake design in the following format.

  • On the ith row, there should be cake along the cells ci,,di, and the rest of the row is empty.
  • On the jth column, there should be cake along the cells rj,,sj, and the rest of the column is empty.

Given Flaco's design, please determine if the design makes sense! A design makes sense if the cake is connected, and it is clear whether a cell is empty or contains cake.

Input Specification

The first line contains two integers R and C.

On the next R lines, the ith line contains ci and di (1cidiC).
On the next C lines, the jth line contains rj and sj (1rjsjR).

Output Specification

Print sense if Flaco's design makes sense.

Otherwise, print nonsense. On the next line, print one of the two following choices:

  • x y, where 1xR and 1yC. This means that the cell at row x, column y is unclear.
  • unconnected, which means that the cake is not connected. Do not use this choice if there is an unclear cell.

Note: If there are multiple unclear cells, any example will be accepted.

Subtasks

Subtask Percentage Additional Constraints
1 30 1R,C10
2 20 1R,C1000
3 50 1R,C105

Sample Input 1

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

Sample Output 1

Copy
nonsense
1 2

Explanation 1

Cake 1 1, 2 2, 2 1, 2
1, 3 C ? C
1, 3 C C C

It is unclear whether the cell at row 1, column 2 is empty or contains cake.

Sample Input 2

Copy
2 2
2 2
1 1
2 2
1 1

Sample Output 2

Copy
nonsense
unconnected

Explanation 2

Cake 2 2, 2 1, 1
2, 2 C
1, 1 C

The cake is not connected.

Sample Input 3

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

Sample Output 3

Copy
sense

Explanation 3

Cake 3 1, 2 2, 2 2, 3 2, 3
1, 1 C
1, 4 C C C C
3, 4 C C

The cake is connected, and it is clear whether a cell is empty or contains cake.


Comments

There are no comments at the moment.