PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#DSU0000012. Tô đỏ các ô (Red Painting)
HỌC THEO LỘ TRÌNH
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Tô đỏ các ô (Red Painting)
Red Painting
Source: AtCoder
Version: Phuoc Hung OJ Extended
Problem Statement
You have an grid whose cells are initially white. Two types of operations are performed:
- Paint a white cell red.
- Ask whether one cell can be reached from another by moving only through red cells, one step at a time to a cell sharing a side.
Answer all connectivity queries in order.
Input
The first line contains two integers . The next line contains an integer . Each of the following lines has one of these forms:
1 r c: paint the cell at row , column red.2 ra ca rb cb: ask about a path between and .
Rows are numbered from to and columns from to . Each cell is painted at most once.
Output
For each operation of type 2, print Yes if such a path exists and No otherwise, one answer per line.
Subtasks
- Subtask 1 (20 points): ; ; ; ; ; every cell is painted at most once.
- Subtask 2 (30 points): ; ; ; ; ; every cell is painted at most once.
- Subtask 3 (50 points): ; ; ; ; ; every cell is painted at most once.
Examples
Input
3 3
6
1 2 2
1 1 2
2 1 2 2 2
1 1 1
2 1 1 2 2
2 1 1 3 3
Output
Yes
Yes
No
Explanation
After painting (2,2) and (1,2), they are connected: Yes. Painting (1,1) also connects it to (2,2): Yes. Cell (3,3) remains white: No.