A necklace in an undirected graph is a sequence of cycles C1, C2, . . . , Ck (k ≥ 1), satisfying the conditions below:
Note that any vertex appears in a cycle at most once. A necklace between two vertices S and T is a necklace C1, C2, . . . , Ck such that S belongs to C1 and T belongs to Ck. Given an undirected graph and two vertices S and T , you need find whether a necklace between S and T exists.
The input consists of multiple test cases. Each test case starts with a line containing two integers N (2 ≤ N ≤ 10, 000) and M (1 ≤ M ≤ 100, 000), which are the number of vertices and the number of edges in the undirected graph, respectively. Each of the following M lines contains two integers A and B (1 ≤ A̸ = B ≤ N ), which indicates an undirected edge between vertices A and B. Vertices are numbered from 1 to N . The last line of each test case contains two integers S and T (1 ≤ S̸ = T ≤ N ). The last test case is followed by a line containing two zeros.
For each test case, print a line containing the test case number (beginning with 1) followed by ‘YES’, if the required necklace exists, otherwise ‘NO’.
範例輸入 1
3 3 1 2 2 3 3 1 1 3 4 5 1 2 2 3 1 3 3 4 3 4 1 4 4 5 1 2 1 2 2 3 3 4 3 4 1 4 0 0
範例輸出 1
Case 1: YES Case 2: YES Case 3: NO
Pro 專屬功能: 查看這題在歷屆 CPE 出現過幾次 — 升級以解鎖.