#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 students in the class. Most of them do not know each other, but there are 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 to . More specifically, for each , students and stand next to each other. Also, students and 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 -th pair of best friends stand at positions and , where .
The teacher chooses two students and and gives a ball to student . The goal is to pass the ball to student , 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 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 to student ?
Input Format
The first line contains three integers , , and , where is the number of students in Anouk’s class, is the number of pairs of best friends, and is the number of games played.
The second line contains integers , where describes the -th pair of best friends. For each , the best friends stand at positions and . Each student has at most one best friend.
The next lines each contain two integers and , the two students chosen in the -th game.
Output Format
Output lines. The -th line should contain one integer, the minimum number of passes needed in the -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 . Student passes the ball to their best friend, student . After student passes the ball to student , the ball reaches student . In total, it takes two passes.
Constraints
For all testdata, , and , , , and .
- Subtask 1 ( points): and . 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 ( points): .
- Subtask 3 ( points): and .
- Subtask 4 ( points): .
- Subtask 5 ( 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