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

Bài tập thuộc lộ trình

1 lộ trình

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 n,cs,ms,C,Mn,c_s,m_s,C,M: room count, cat and mouse homes, counts of cat doors and mouse doors, followed by CC directed cat doors and MM directed mouse doors.

Output

Print two space-separated Y/N characters: possible meeting and possible safe mouse cycle.

Subtasks

  • Subtask 1 (40 points): n≤12n\le12, C,M≤25C,M\le25; 1≤n≤1001\le n\le100, 1≤cs,ms≤n1\le c_s,m_s\le n, 0≤C,M≤10000\le C,M\le1000; doors connect distinct rooms numbered 1…n1\ldots n.
  • Subtask 2 (60 points): 1≤n≤1001\le n\le100, 1≤cs,ms≤n1\le c_s,m_s\le n, 0≤C,M≤10000\le C,M\le1000; doors connect distinct rooms numbered 1…n1\ldots n.

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.