#P16708. [SEATST 2026] 麻烦的旅程 / Troublesome Trip
[SEATST 2026] 麻烦的旅程 / Troublesome Trip
Problem Description
A unique and mysterious species called Nuko lives on an archipelago in a remote corner of the world. The archipelago can be modeled as islands, numbered from to , connected by bridges. For all , bridge connects islands and in both directions. It is guaranteed that you can travel from any island to any other island. Each bridge connects two different islands, and no two bridges connect the same pair of islands.
In ancient times, Nukos lived only on island . However, as time passed, Nukos spread to all islands. Whenever a group of Nukos crosses a bridge and reaches a new island, they evolve and form a subspecies different from the one on the previous island. More precisely, for all , the Nukos on island belong to subspecies , where is the minimum number of bridges that must be crossed to reach island from island . For example, the Nukos on island belong to subspecies .
You are a traveler and plan to use these bridges to travel from island to island . It is guaranteed that . When you are on an island, you will inevitably encounter the Nuko subspecies living there. Since each subspecies has its own customs that you need to adapt to, and adapting to different customs can be troublesome, your goal is to choose a path that minimizes the number of distinct Nuko subspecies you encounter.
Can you compute the minimum possible number of distinct Nuko subspecies you must encounter when traveling from island to island ?
Implementation Details
You need to implement the following function.
int min_distinct(int N, int M, int A, int B, std::vector<int> U, std::vector<int> V)
- : the number of islands.
- : the number of bridges.
- : the starting island of your trip.
- : the destination island of your trip.
- , : arrays of length describing the bridges.
- This function should return the minimum number of distinct Nuko subspecies you must encounter.
Input Format
N M A B
U[0] V[0]
U[1] V[1]
...
U[M - 1] V[M - 1]
Output Format
An integer, representing the return value of the min_distinct function.
Hint
Samples
Consider the following function call.
min_distinct(5, 5, 2, 4, [0, 1, 2, 3, 4], [1, 2, 3, 4, 0])
The diagram of the islands is as follows, where different shadings represent different Nuko subspecies.
:::align{center}
:::
For sample , the optimal path is . The Nuko subspecies encountered are and . Therefore, this call should return .
min_distinct(8, 9, 4, 7, [0, 0, 0, 1, 1, 2, 2, 6, 7], [1, 2, 3, 4, 5, 5, 6, 3, 3])
The diagram of the islands is as follows, where different shadings represent different Nuko subspecies.
:::align{center}
:::
For sample , the optimal path is . The Nuko subspecies encountered are and . Therefore, this call should return .
min_distinct(15, 17, 3, 7,
[0, 1, 2, 3, 4, 13, 12, 12, 11, 10, 10, 9, 8, 7, 6, 8, 0],
[1, 2, 3, 4, 13, 12, 1, 11, 10, 9, 5, 8, 7, 6, 5, 14, 14])
For sample , when traveling from island to island , the minimum number of distinct Nuko subspecies you must encounter is . Therefore, this call should return .
Constraints
- .
- .
- .
- .
- For all , .
- For all , .
- For all and , and .
- It is guaranteed that you can travel from any island to any other island.
Subtasks
- ( points) .
- ( points) .
- ( points) .
- ( points) .
- ( points) .
- ( points) .
- ( points) .
- ( points) .
- ( points) No additional constraints.
Note: For subtask , the judge will use ms out of the ms time limit.
Translated by ChatGPT 5