PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#FW0000041. Mèo và chuột (Cat and Mouse)
HỌC THEO LỘ TRÌNH
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Mèo và chuột (Cat and Mouse)
Cat and Mouse
Source: UVa
Version: Phuoc Hung OJ Extended
Problem Statement
Cat and mouse use separate directed doors. Decide whether their reachable sets intersect, and whether the mouse can make a nonempty closed walk from its home avoiding every room reachable by the cat.
Input
Integers : room count, cat and mouse homes, counts of cat doors and mouse doors, followed by directed cat doors and directed mouse doors.
Output
Print two space-separated Y/N characters: possible meeting and possible safe mouse cycle.
Subtasks
- Subtask 1 (40 points): , ; , , ; doors connect distinct rooms numbered .
- Subtask 2 (60 points): , , ; doors connect distinct rooms numbered .
Examples
Input
5 3 5 5 6
1 2
2 1
3 1
4 3
5 2
1 3
2 5
3 4
4 1
4 5
5 4
Output
Y Y
Explanation
The cat can reach rooms 1,2,3 and may meet the mouse there. The mouse also has the safe cycle 5 to 4 to 5, avoiding all rooms accessible to the cat.