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

문제

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 $2N$ 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 $2N - 1$. More specifically, for each $0 \leq i < 2N - 1$, students $i$ and $i + 1$ stand next to each other. Additionally, students $0$ and $2N - 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 $2N$ 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.

채점 및 기타 정보

  • 예제는 채점하지 않는다.