#P10848. [EGOI 2024] Circle Passing / 传球游戏

[EGOI 2024] Circle Passing / 传球游戏

Background

Day 2 Problem A.

The statement is translated from EGOI2024 circlepassing. The translation comes from ChatGPT and has been manually proofread. If there are any mistakes, please contact rui_er.

Problem Description

This is Anouk’s first day at high school. As a warm-up activity, her PE teacher has the class play a game to remember names. There are 2N2N students in the class. Most of them do not know each other, but there are MM pairs of best friends who do everything together. Each student has at most one best friend.

The teacher arranges all students in a circle and assigns each student a consecutive number from 00 to 2N12N - 1. More specifically, for each 0i<2N10 \le i < 2N - 1, students ii and i+1i + 1 stand next to each other. Also, students 00 and 2N12N - 1 stand next to each other.

Since the teacher wants everyone to meet new classmates, best friends must be as far apart as possible, i.e., they stand opposite each other. That is, the students forming the ii-th pair of best friends stand at positions kik_i and ki+Nk_i + N, where 0ki<N0 \le k_i < N.

The teacher chooses two students xx and yy and gives a ball to student xx. The goal is to pass the ball to student yy, 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 teacher explains the rules, each student learns the names of the two students standing directly next to them. Other than that, nobody knows anyone else’s name.

The game is played QQ times. Each time, the teacher chooses two students. Since the students are not paying attention, they do not learn any new names during the games. In each game, what is the minimum number of passes needed to get the ball from student xx to student yy?

Input Format

The first line contains three integers NN, MM, and QQ, where 2N2N is the number of students in Anouk’s class, MM is the number of pairs of best friends, and QQ is the number of games played.

The second line contains MM integers k0,,kM1k_0,\cdots,k_{M-1}, where kik_i describes the ii-th pair of best friends. For each ii, the best friends stand at positions kik_i and ki+Nk_i + N. Each student has at most one best friend.

The next QQ lines each contain two integers xix_i and yiy_i, the two students chosen in the ii-th game.

Output Format

Output QQ lines. The ii-th line should contain one integer, the minimum number of passes needed in the ii-th game.

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

2
1
2
1
2
6 1 3
5
5 7
5 1
5 11
2
3
1
4 2 4
2 3
0 2
0 3
0 6
0 7
2
2
2
1
5 2 5
0 4
0 9
1 8
8 3
1 6
3 9
1
3
3
3
2
500000000 4 3
543234 1234566 2300001 249999999
2334445 123567
6578996 12455726
3 269979899
2210878
5876730
231106567

Hint

Sample Explanation

The following two figures show the arrangements for Sample 1 and Sample 4. If two students know each other, there is an edge connecting them.

In the first query of Sample 1, the ball is passed to student 11. Student 11 passes the ball to their best friend, student 55. After student 55 passes the ball to student 44, the ball reaches student 44. In total, it takes two passes.


Constraints

For all testdata, 2N5×1082\le N\le 5\times 10^8, 1M5×1051\le M\le 5\times 10^5 and MNM\le N, 1Q2×1041\le Q\le 2\times 10^4, 0k0<k1<<kM1<N0\le k_0<k_1<\cdots<k_{M-1}<N, 0xi,yi<2N0\le x_i,y_i < 2N and xiyix_i\ne y_i.

  • Subtask 1 (1414 points): M=1M=1 and xi=k0x_i=k_0. In other words, there is only one pair of best friends, and in every game, the student who starts with the ball has a best friend.
  • Subtask 2 (2020 points): N,M,Q1000N,M,Q\le 1000.
  • Subtask 3 (2222 points): N107N\le 10^7 and M,Q1000M,Q\le 1000.
  • Subtask 4 (1717 points): xi=0x_i=0.
  • Subtask 5 (2727 points): No additional constraints.

Note: Some test points were included in multiple subtasks in EGOI. To save judging resources and effort in organizing the data, these test points are placed in the subtask with the smallest index among all subtasks that contain them. This may cause a solution to get a higher score than expected, but still not pass the problem.

Translated by ChatGPT 5