• [1092] Find the Marble

  • 时间限制: 2000 ms 内存限制: 65535 K
  • 问题描述
  • Alice and Bob are playing a game. This game is played with several identical pots and one marble. When the game starts, Alice puts the pots in one line and puts the marble in one of the pots. After that, Bob cannot see the inside of the pots. Then Alice makes a sequence of swappings and Bob guesses which pot the marble is in. In each of the swapping, Alice chooses two different pots and swaps their positions.

    Unfortunately, Alice's actions are very fast, so Bob can only catch k of m swappings and regard these k swappings as all actions Alice has performed. Now given the initial pot the marble is in, and the sequence of swappings, you are asked to calculate which pot Bob most possibly guesses. You can assume that Bob missed any of the swappings with equal possibility.

  • 输入
  • There are several test cases in the input file. The first line of the input file contains an integer N (N ≈ 100), then N cases follow.

    The first line of each test case contains 4 integers n, m, k and s(0 < s ≤ n ≤ 50, 0 ≤ k ≤ m ≤ 50), which are the number of pots, the number of swappings Alice makes, the number of swappings Bob catches and index of the initial pot the marble is in. Pots are indexed from 1 to n. Then m lines follow, each of which contains two integers ai and bi (1 ≤ ai, bi ≤ n), telling the two pots Alice swaps in the i-th swapping.
  • 输出
  • For each test case, output the pot that Bob most possibly guesses. If there is a tie, output the smallest one.
  • 样例输入
  • 3
    3 1 1 1
    1 2
    3 1 0 1
    1 2
    3 3 2 2
    2 3
    3 2
    1 2
  • 样例输出
  • 2
    1
    3
    
  • 提示
  • 来源
  • [ZJU]GUAN, Yao
  • 操作

显示春菜