Rigging Elections

Elections in your country are performed in a one-on-one elimination style. Each week, two people are chosen from a pool of candidates and the country votes on which one they prefer. The loser is elim- inated and the winner is returned to the pool of candidates. This process contin- ues until only one candidate remains. To make a bad voting system even worse, a single person is charged with the responsibility of choosing the two candi- dates each week. This person happens to be you! Since you are a very selfish per- son, you plan on rigging the election so your preferred candidate wins. You have access to polling data from which you can determine who would win in every possible head-to-head matchup. Assuming the data accurately rep- resents what the real outcome would be, is it possible to schedule the candidates so your candidate wins? 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. Here, n indicates the total number of candidates in the initial pool, m is the number of voters and c is the number of your preferred candidate. This is followed by m lines, each containing a permutation of the numbers 1 through n. The i-th line should be interpreted as a ranking of the n candidates by voter i. If two candidates are pitted against each other in an election, then voter i will vote for whoever appears first in their 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 rig the elections so your preferred candidate c wins. Sample Input 331 123 231 312 331 123 231 321 000

2/2 Sample Output yes no