#P9370. [APIO2023] 赛博乐园 / cyberland
[APIO2023] 赛博乐园 / cyberland
Background
Due to some BUGs, submitting with C++14 (GCC9) will cause a compilation error. Please use C++14 and other languages to submit.
When submitting, you do not need to include cyberland.h. In your submitted code, you need to implement the following function:
double solve(int N, int M, int K, int H, std::vector<int> x, std::vector<int> y, std::vector<int> c, std::vector<int> arr)
Problem Description
The year 3742 has arrived, and now it is Cyberland’s turn to host APIO. In this world, there are countries, numbered from to , and there are bidirectional roads (each edge can be traveled in both directions), numbered from to . Each road connects two different countries, and , and it takes time to travel along that road. All contestants, except the one from your country, have already gathered in Cyberland to attend APIO. You live in country , and Cyberland is country . As the smartest person in your country, your help is urgently needed. More specifically, you need to determine the minimum time required to reach Cyberland from your country.
When passing through some countries, you can reset your current total travel time. Also, some other countries can divide your current total travel time by when you pass through them (we call this the “divide-by-2 ability”). You may pass through a country multiple times. Each time you pass through a country, you may choose whether to use that country’s special ability. However, each time you pass through a country, you can use its special ability at most once (if you pass through a country multiple times, you may use its special ability at most once each time). In addition, to avoid being caught by the Cyberland Chemical Foundation, you may use the “divide-by-2 ability” at most times. Once you arrive in Cyberland, you cannot move anywhere else, because the great APIO contest is about to begin.
You are given an array , where represents the special ability of country . Each country has one of the following special abilities:
- means this country can set the current total travel time to .
- means this country does not change your current total travel time.
- means this country has the ability to divide the current total travel time by .
It is guaranteed that . In other words, neither Cyberland nor your home country has any special ability.
Your country does not want to miss any moment of APIO, so you need to find the shortest time to reach Cyberland. If you cannot reach Cyberland, your answer should be .
Implementation Details
You need to implement the following function:
double solve(int N, int M, int K, int H, std::vector<int> x, std::vector<int> y, std::vector<int> c, std::vector<int> arr);
- : the number of countries.
- : the number of bidirectional roads.
- : the maximum number of times the “divide-by-2 ability” can be used.
- : the index of the country “Cyberland”.
- : three arrays of length . The triplet indicates that the -th bidirectional edge connects countries and , and the time cost to travel through it is .
- : an array of length . indicates the special ability of country .
- If you can reach Cyberland, the function should return the shortest time needed to travel from your country to Cyberland; otherwise, return .
- This process may be called multiple times.
Suppose the contestant’s answer is , and the standard output is . Your output is considered correct if and only if $\dfrac{|ans_1-ans_2|}{\max\{ans_2,1\}} \le 10 ^ {-6}$.
Note: Since the function may be called multiple times, contestants need to be careful about the impact of leftover data from previous calls on subsequent calls.
Input Format
The sample grader reads input in the following format:
- Line :
For each of the test cases:
- Line :
- Line :
- Line :
- Line :
Output Format
The sample grader prints your answer in the following format:
For each test case:
- Line : the return value of
solve.
3 2 30
2
1 2 1
1 2 12
2 0 4
4
4 4 30
3
1 0 2 1
0 1 5
0 2 4
1 3 2
2 3 4
2
Hint
Examples
Sample 1
Consider the following call:
solve(3, 2, 30, 2, {1, 2}, {2, 0}, {12, 4}, {1, 2, 1});
The only path to reach Cyberland is , because after you arrive in Cyberland you cannot move to any other place. The travel time is computed as follows:
| Country index | Travel time |
|---|---|
| $0 + 4 \rightarrow 4(\text{sum}) \rightarrow 4(\text{special ability})$ | |
Sample 2
Consider the following call:
solve(4, 4, 30, 3, {0, 0, 1, 2}, {1, 2, 3, 3}, {5, 4, 2, 4}, {1, 0, 2, 1});
There are two paths from your country to Cyberland: and .
If you choose the path , the travel time is computed as follows:
| Country index | Travel time |
|---|---|
| $0 + 5 \rightarrow 5(\text{sum}) \rightarrow 0(\text{special ability})$ | |
| $0 + 2 \rightarrow 2(\text{sum}) \rightarrow 2(\text{special ability})$ | |
If you choose the path , the travel time is computed as follows:
| Country index | Travel time |
|---|---|
| $0 + 4 \rightarrow 4(\text{sum}) \rightarrow 2(\text{special ability})$ | |
| $2 + 4 \rightarrow 6(\text{sum}) \rightarrow 6(\text{special ability})$ | |
Therefore, the above call should return .
Constraints
- .
- $0 \le M \le \min\{10^5, \dfrac{N(N-1)}{2} \}, \sum M \le 10^5$.
- .
- .
- .
- .
- .
- It is guaranteed that there is at most one road connecting any pair of countries.
Subtasks
- (5 points): .
- (8 points): . You can travel from any country to any other country using these roads.
- (13 points): . You can travel from any country to any other country using these roads.
- (19 points): .
- (7 points): .
- (16 points): .
- (29 points): .
- (3 points): No special constraints.
Translated by ChatGPT 5