Delicious Food
Time Limit: 3 Seconds Memory Limit: 131072 KB
Your university has changed its food providing system and ran a one-on-one elimination online voting system to find out the most preferred food for each day. In this system, each time, two foods are chosen from a set of different kind of foods and students vote on which they prefer. The loser (less preferred) food is eliminated and the winner is returned to the food set. This process continues until only one food remains (It must be so delicious!).
One day, when you are going to vote for your food, the security module crashes and now you have access to all the information kept in the voting system such as students’ food preferences and the set of foods that is going to be voted. Surprisingly, you have access to control which two foods to show each time for voting. How such an access! It’s time to eat your most preferred food for lunch in the next day. Is there any way to control food selection so your beloved food be the winner?
Input
The first line of each test case, contains three integers n, m, and c with 1 <= n <= 100, 1 <= m <= 100 and 1 <= c <= n, which, n indicates the total number of foods in the food set, m is the number of students and c is the number of the food you love to eat (foods are numbered from 1 to n). This is followed by m lines, each containing a permutation of the numbers 1 through n. The ith line should be interpreted as a ranking of the foods in the set by the student i. If two foods are pitted against each other, then student i will vote for the one appears before the other one in their rank (preference) list. You may also assume m is always odd. The last line of input contains three zeros and should not be processed.
Output
There is a single line of output for each test case with either the message yes or no indicating if it is possible for you to eat your preferred food next day or not.
Sample Input
4 3 1 1 2 3 4 2 3 1 4 3 4 1 2 4 3 4 1 2 3 4 2 3 1 4 3 4 1 2 0 0 0
Sample Output
yes noSubmit