PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#CC0000005. Thu gọn bảng thẻ (Reorder Cards)
HỌC THEO LỘ TRÌNH
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Thu gọn bảng thẻ (Reorder Cards)
Reorder Cards
Source: AtCoder Version: Phuoc Hung OJ Extended
Problem Statement
An by grid contains numbered cards at distinct cells . Remove every row and column containing no numbered card, shifting the remaining rows upward and columns leftward. Determine the final position of every numbered card while keeping their relative order.
Input
The first line contains , , . Each of the next lines gives row and column of card .
Output
Print lines. Line contains the new row and column of card .
Subtasks
- Subtask 1 (20 points): ; ; , ; all distinct.
- Subtask 2 (30 points): ; ; , ; all distinct.
- Subtask 3 (50 points): ; ; , ; all distinct.
Examples
Input
5 7 3
2 4
5 1
2 7
Output
1 2
2 1
1 3
Explanation
Keep only rows and columns . Card one moves from to .