#P14038. [PAIO 2025] Adventure Plan
[PAIO 2025] Adventure Plan
题目描述
Adventure Plan
You are preparing for an adventure. The adventure is a journey from the start vertex to the end vertex, hosted on a directed acyclic graph (DAG). The DAG has vertices numbered from to and edges. The starting vertex is vertex , and all vertices are reachable from the start.
Each directed edge from to has two attributes: and . It indicates the minimum and maximum time required to safely pass through the edge. Therefore, you may set the planned time for this edge to any integer in the interval .
Lots of your friends are also preparing for the adventure. Each of them will take a different route from the start to the end. To ensure safety, you hope that friends taking different routes can meet at each vertex simultaneously. That is, you want to set the planned time for each edge such that for every vertex , all paths from the start to have the same total time.
We call a graph safe if it satisfies the requirement. It is guaranteed that the initial graph is safe.
Task 1
You want to add some new edges to the graph to make it more interesting. You will perform operations of "adding new edges." Each operation provides a new directed edge . You know that after adding this edge, the graph remains a directed acyclic graph, but you are not sure whether the graph is still safe. Please determine whether the graph is safe after adding this edge. If it is, add the edge to the graph. If not, you should ignore this operation.
Task 2
After all operations, you need to output the planned time for each edge (including the newly added ones) to prove that you are sure the new graph is safe.
Implementation Details
You need to implement two procedures.
The first procedure you need to implement is add_roads
:
boolean[] add_roads(int32 N, int32 M, int32 Q,
int32[] U, int32[] V,
int32[] L, int32[] R,
int32[] U2, int32[] V2,
int32[] L2, int32[] R2);
- : the number of vertices;
- : the number of initial edges;
- : the number of operations;
- : arrays of length , where represents the -th directed edge;
- : arrays of length , where is the feasible interval of times for edge ;
- : arrays of length , describing the new edges;
- This procedure is called exactly once for each test case at the beginning of the program.
The procedure should return a vector of length , where the -th element is true if the -th operation edge is added, or false otherwise.
The second procedure you need to implement is assign_times
:
int32[] assign_times();
- This procedure is called exactly once for each test case after
add_roads
is called.
The procedure should return a vector containing the planned time for each edge that is present in the final graph (in any valid order).
提示
Examples
Example 1:
Consider the following call.
add_roads(4, 4, 2,
[0, 1, 0, 0],
[1, 3, 3, 2],
[1, 3, 9, 6],
[5, 7, 14, 8],
[2, 2],
[3, 1],
[7, 5],
[11, 7]);
The procedure should return [false, true]
.
Consider the following input after add_roads
is called.
assign_times();
The procedure should return [5, 7, 12, 6, 6]
.
Sample Grader
The sample grader reads the input in the following format:
- Line 1: Three integers , and
- Next lines: four integers describing each edge
- Next lines: four integers describing each operation
Constraints
Scoring
- Subtask 1 (7 points):
- Subtask 2 (21 points):
- Subtask 3 (12 points):
- Subtask 4 (11 points):
- Subtask 5 (24 points):
- Subtask 6 (25 points): No additional constraints