407540: GYM102823 I Item Exchange

Memory Limit:256 MB Time Limit:5 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

I. Item Exchangetime limit per test5 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard output

There are $$$n$$$ people sitting in a line. They are numbered from $$$1$$$ to $$$n$$$ from the left to right. For each person $$$i$$$, there is an item in his hands and also numbered $$$i$$$.

Each person has a "preference list" which is a permutation of $$$1, \dots, n$$$. The preference list describes one's preference for those items, i.e. if $$$i$$$ appears more formerly than $$$j$$$ in one's list, we could say that he prefer item $$$i$$$ than item $$$j$$$.

As the people can see the item in his neighbor's hand, if there are two persons (who are neighbors) both prefer the item in each other's hand, they can exchange their items.

Now given the preference lists of all the people, and two integers $$$i$$$, $$$j$$$, you have to answer whether there is an exchange scheme that person $$$j$$$ owns item $$$i$$$ at some moment.

Input

The first line of input file contains an integer $$$T$$$ ($$$1 \leq T \leq 85$$$), describing the number of test cases.

For each test case, there are several lines.

First of them contains only one integer $$$n$$$ ($$$1\le n \le 200$$$) described above.

Then following $$$n$$$ lines with $$$n$$$ numbers ranging from $$$1$$$ to $$$n$$$ each line. The $$$i$$$-th line of those describing the "preference list" of person $$$i$$$ ($$$1\le i \le n$$$).

And the $$$(n+2)$$$-th line contains two integers $$$i$$$ and $$$j$$$ ($$$1\le i\le n$$$, $$$1\le j\le n$$$) described above.

There are no more than 14 test cases that $$$n \geq 100$$$.

Output

You should output exactly $$$T$$$ lines.

For each test case, print Case $$$d$$$: ($$$d$$$ represents the order of case) first, and then print the answer, Yes or No, on the same line.

ExampleInput
3

3
3 1 2
1 3 2
2 3 1
1 2

3
3 1 2
1 3 2
2 3 1
1 3

4
3 1 2 4
4 1 3 2
1 4 2 3
2 4 1 3
1 3
Output
Case 1: Yes
Case 2: No
Case 3: Yes
Note

There is a possible scheme for Sample 3:

$$$(1,\underline{2,3},4)\rightarrow(\underline{1,3},2,4)\rightarrow(3,1,\underline{2,4})\rightarrow(3,\underline{1,4},2)\rightarrow(3,4,1,2)$$$

加入题单

上一题 下一题 算法标签: