LCC/Moose '20 Contest 3 J1 - Cup Swapping

View as PDF

Submit solution

Points: 3
Time limit: 2.0s
Memory limit: 64M

Author:
Problem type

You have 3 cups in a line. Only one of these cups will contain a ball, and the ball will be in the Kth. cup from the left. Your friend decides to mess with you, and while you weren't looking they swapped two cups at random, N times. However, you had a camera that was able to keep track of all of the switches. Using this, can you determine which cup contains the ball after the switches, counting from left to right?

Input Specification

The first line will contain N (0 \leq N \leq 100), the number of swaps that your friend made, and K (1 \leq K \leq 3), the cup that contains the ball counting from the left.

The next N lines will each contain 2 integers, a_i and b_i (1 \leq a_i, b_i \leq 3, a_i \neq b_i), the cups that were swapped by your friend in the specific swap.

Output Specification

One integer, the index of the cup that contains the ball, counting from the left.

Sample Input 1

3 1
1 2
2 3
1 2

Sample Output 1

3

Sample Explanation

The ball starts off in cup 1. After the first swap, the ball is now in cup 2. After the second, the ball is now in cup 3. The third swap does not affect which ball the cup is in, so finally the answer is 3.


Comments

There are no comments at the moment.