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

32444번 - Circle Passing 서브태스크다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
2 초 1024 MB96666.667%

문제

It is the first day of high school for Anouk; as a warm-up activity, her sports teacher is making the class play name-learning games. There are 2ドルN$ students in the class. Most of them do not know each other, but there are $M$ pairs of best friends who do everything together. Each student has at most one best friend.

The teacher arranges all of the students in a circle, consecutively assigning each student a number from 0ドル$ to 2ドルN - 1$. More specifically, for each 0ドル \leq i < 2N - 1,ドル students $i$ and $i + 1$ stand next to each other. Additionally, students 0ドル$ and 2ドルN - 1$ stand next to each other.

Since the teacher wants everyone to meet new students, best friends have to stand as far away from each other as possible, i.e. opposite each other. That is, the students forming the $i$th pair of best friends are standing at positions $k_i$ and $k_i + N$ respectively, where 0ドル \leq k_i < N$.

The teacher selects two students $x$ and $y$ and hands a ball to student $x$. The goal is to send the ball to student $y,ドル but each student may only pass the ball to another student whose name they already know. Of course, best friends know each other's names. While the rules were explained, each student got to know the names of the two students standing directly beside them. Other than that, no one knows any other names.

The game is played $Q$ times; the teacher chooses two students each time. Since the students are not paying attention, they do not learn any new names throughout the games. What is the minimum number of passes needed to get the ball from student $x$ to student $y$ in each game?

입력

The first line of input contains three integers, $N,ドル $M$ and $Q,ドル where 2ドルN$ is the number of students in Anouk's class, $M$ is the number of pairs of best friends, and $Q$ is the number of games that are played.

The second line contains $M$ integers $k_0, \ldots, k_{M-1},ドル with $k_i$ describing the $i$th pair of best friends. For each $i,ドル the best friends stand at positions $k_i$ and $k_i + N$ respectively. Each student has at most one best friend.

The following $Q$ lines each contain two integers, $x_i$ and $y_i,ドル the two selected students in game $i$.

출력

Output $Q$ lines, the $i$th line containing a single integer, the minimum number of passes needed in game $i$.

제한

  • 2ドル \leq N \leq 5 \cdot 10^8$.
  • 1ドル \leq M \leq 5 \cdot 10^5$ and $M \le N$.
  • 1ドル \leq Q \leq 2 \cdot 10^4$.
  • 0ドル \leq k_0 < k_1 < \ldots < k_{M - 1} < N$.
  • 0ドル \leq x_i, y_i < 2N$ with $x_i \neq y_i$.

서브태스크

번호배점제한
114

$M = 1$ and $x_i = k_0$. In other words, there is a single pair of best friends, and in every game, the student starting with the ball has a best friend.

220

$N,M,Q \leq 1000$

322

$N \leq 10^7$ and $M,Q\leq 1000$

417

$x_i = 0$ for all $i$

527

No additional constraints

예제 입력 1

4 1 5
1
1 4
1 5
1 7
1 2
1 6

예제 출력 1

2
1
2
1
2

예제 입력 2

6 1 3
5
5 7
5 1
5 11

예제 출력 2

2
3
1

예제 입력 3

4 2 4
2 3
0 2
0 3
0 6
0 7

예제 출력 3

2
2
2
1

예제 입력 4

5 2 5
0 4
0 9
1 8
8 3
1 6
3 9

예제 출력 4

1
3
3
3
2

예제 입력 5

500000000 4 3
543234 1234566 2300001 249999999
2334445 123567
6578996 12455726
3 269979899

예제 출력 5

2210878
5876730
231106567

노트

The following two figures depict the arrangements in the first and the fourth sample. Two students are connected by an edge if they know each other's names.

In the first game of the first sample, the ball is given to student 1ドル$. Student 1ドル$ passes the ball to their best friend, student 5ドル$. The ball reaches student 4ドル$ after student 5ドル$ passes it to them, needing two passes in total.

출처

Olympiad > European Girls' Olympiad in Informatics > EGOI 2024 > Day 2 A번

채점 및 기타 정보

  • 예제는 채점하지 않는다.
(追記) (追記ここまで)

출처

대학교 대회

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

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