#P14038. [PAIO 2025] Adventure Plan

    ID: 15832 远端评测题 3000ms 2048MiB 尝试: 0 已通过: 0 难度: 5 上传者: 标签>2025交互题Special Judge最短路负权环差分约束PAIO

[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 nn vertices numbered from 00 to n1n-1 and mm edges. The starting vertex is vertex 00, and all vertices are reachable from the start.

Each directed edge from uiu_i to viv_i has two attributes: lil_i and rir_i. 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 tit_i in the interval [li,ri][l_i, r_i].

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 uu, all paths from the start to uu 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 qq operations of "adding new edges." Each operation provides a new directed edge (ui,vi,li,ri)(u_i, v_i, l_i, r_i). 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);
  • NN: the number of vertices;
  • MM: the number of initial edges;
  • QQ: the number of operations;
  • U,VU, V: arrays of length MM, where (U[i],V[i])(U[i], V[i]) represents the ii-th directed edge;
  • L,RL, R: arrays of length MM, where [L[i],R[i]][L[i], R[i]] is the feasible interval of times for edge ii;
  • U2,V2,L2,R2U2, V2, L2, R2: arrays of length QQ, 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 QQ, where the ii-th element is true if the ii-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 tit_i 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 n,mn, m, and qq
  • Next mm lines: four integers ui,vi,li,riu_i, v_i, l_i, r_i describing each edge
  • Next qq lines: four integers ui,vi,li,riu_i, v_i, l_i, r_i describing each operation

Constraints

  • 3n5003 \le n \le 500
  • n1m105n-1 \le m \le 10^5
  • 0q5000 \le q \le 500
  • 0ui<n0 \le u_i < n
  • 1liri1091 \le l_i \le r_i \le 10^9

Scoring

  1. Subtask 1 (7 points): n3n \le 3
  2. Subtask 2 (21 points): q=0q = 0
  3. Subtask 3 (12 points): vi=ui+1v_i = u_i + 1
  4. Subtask 4 (11 points): li=ril_i = r_i
  5. Subtask 5 (24 points): n100,m100,q100n \le 100, m \le 100, q \le 100
  6. Subtask 6 (25 points): No additional constraints