Logo
(追記) (追記ここまで)

34416번 - Follow The Prize 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
7 초 2048 MB120997984.946%

문제

A total of $n$ cups were placed upside-down on a table, a prize was placed under one of them, and then the cups were shuffled. Luckily, you know under which cup the prize began, and how the cups were shuffled. Can you determine the final position of the prize?

A cup (and the prize which it might cover) can only be in one of $n$ distinct positions at any given time: 1,ドル 2, \ldots, n$. No two cups can be in the same position at any given time.

The cups are shuffled by performing a series of swaps. A swap is defined as exchanging the location of two cups. For example if the cups in positions 4ドル$ and 7ドル$ were swapped, the cup originally in position 4ドル$ would end in position 7ドル,ドル and the cup originally in position 7ドル$ would end in position 4ドル$. If the prize were originally under cup 7ドル,ドル this swap would have moved the prize to position 4ドル$.

입력

The first line is $n,ドル an integer between 2ドル$ and 1ドル,000円,000円,ドル inclusive, defining the number of cups.

The second line is an integer between 1ドル$ and $n,ドル inclusive, which defines the initial position of the prize.

The third line is $m,ドル a non-negative integer less than or equal to 1ドル,000円,000円,ドル defining the number of swaps performed to shuffle the cups.

The final $m$ lines report the swaps that were performed, in order. Each line consists of two different space-separated integers, between 1ドル$ and $n,ドル defining the positions of the cups that were exchanged for that swap.

출력

The output is a single integer between 1ドル$ and $n,ドル which is the position of the prize after all of the swaps are performed.

제한

예제 입력 1

3
2
3
1 2
3 2
1 3

예제 출력 1

3

노트

출처

School > CS@Mines > CS@Mines HSPC 2021 F번

  • 문제를 만든 사람: Colin Siles
(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /