CF2239E.The end of this world,

NOI/NOI+/CTSC

通过率:0%

时间限制:5.00s

内存限制:1024MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

... and the girl who crossed the moon's oceans.

— Frums

You are given an undirected graph consisting of nn vertices and mm edges. The ii-th vertex has an associated value vali\mathrm{val}_i. The jj-th edge connects vertices uju_j and vjv_j and has two properties: a capacity wjw_j and a floor lowj\mathrm{low}_j. It is guaranteed that wj≥lowjw_j \ge \mathrm{low}_j for all edges.

You want to start a walk from a vertex ss. Before the walk begins, you must choose an arbitrary non-negative integer hstarth_{start} as your initial state parameter.

If you are currently at vertex uu with state hh, you can traverse an edge jj connecting uu and vv if and only if wj≥hw_j \ge h. Upon traversing this edge and arriving at vertex vv, the state parameter hh updates to max⁡(h,lowj)\max(h, \mathrm{low}_j).

Let the walk end at some vertex tt. You must traverse at least one edge. The score of such a walk is defined as valt+hstart\mathrm{val}_t + h_{start}. Note that we are interested in the sum of the final vertex value and the initial state parameter, not the final state parameter.

For each starting vertex ss from 11 to nn, calculate the maximum possible score achievable. If it is impossible to traverse any edge starting from some ss, output −1-1 instead.

……以及那位穿越月球海洋的女孩。

— Frums

给定一个包含 nn 个顶点和 mm 条边的无向图。第 ii 个顶点关联一个值 vali\mathrm{val}_i。第 jj 条边连接顶点 uju_j 和 vjv_j,并具有两个属性:容量 wjw_j 和下界 lowj\mathrm{low}_j。保证对所有边均有 wj≥lowjw_j \ge \mathrm{low}_j。

你希望从某个顶点 ss 出发开始一次行走。在行走开始前,你必须任选一个非负整数 hstarth_{start} 作为初始状态参数。

若当前位于顶点 uu 且状态为 hh,则当且仅当 wj≥hw_j \ge h 时,你才能沿第 jj 条边(连接 uu 和 vv)行进。当你经该边抵达顶点 vv 后,状态参数 hh 更新为 max⁡(h,lowj)\max(h, \mathrm{low}_j)。

设该行走终止于某个顶点 tt。你必须至少经过一条边。此类行走的得分定义为 valt+hstart\mathrm{val}_t + h_{start}。注意:我们关心的是终点顶点的值与初始状态参数之和,而非最终状态参数。

对每个起始顶点 ss(从 11 到 nn),计算所能达到的最大得分。若从某个 ss 出发无法经过任何边,则输出 −1-1。

输入格式

Each test contains multiple test cases. The first line contains the number of test cases tt (1≤t≤1041 \le t \le 10^4). The description of the test cases follows.

The first line of each test case contains two integers nn and mm (1≤n≤5⋅105,0≤m≤5⋅1051 \le n \le 5\cdot 10^5, 0 \le m \le 5\cdot 10^5) — the number of vertices and the number of edges.

The second line of each test case contains nn integers val1,val2,…,valn\mathrm{val}_1, \mathrm{val}_2, \ldots, \mathrm{val}_n (1≤vali≤1091 \le \mathrm{val}_i \le 10^9) — the values of the vertices.

The next mm lines describe the edges. The jj-th line contains four integers uj,vj,wj,lowju_j, v_j, w_j, \mathrm{low}_j (1≤uj,vj≤n,uj≠vj1 \le u_j, v_j \le n, u_j \neq v_j; 1≤lowj≤wj≤1091 \le \mathrm{low}_j \le w_j \le 10^9) — the endpoints and properties of the jj-th edge.

The graph is not guaranteed to be connected and may contain multiple edges.

It is guaranteed that the sum of nn and the sum of mm over all test cases do not exceed 5⋅1055\cdot 10^5.

每个测试包含多个测试用例。第一行包含测试用例数量 tt(1≤t≤1041 \le t \le 10^4)。随后是各测试用例的描述。

每个测试用例的第一行包含两个整数 nn 和 mm(1≤n≤5⋅105, 0≤m≤5⋅1051 \le n \le 5\cdot 10^5,\ 0 \le m \le 5\cdot 10^5)——分别表示顶点数和边数。

每个测试用例的第二行包含 nn 个整数 val1,val2,…,valn\mathrm{val}_1, \mathrm{val}_2, \ldots, \mathrm{val}_n(1≤vali≤1091 \le \mathrm{val}_i \le 10^9)——表示各顶点的权值。

接下来的 mm 行描述边的信息。第 jj 行包含四个整数 uj,vj,wj,lowju_j, v_j, w_j, \mathrm{low}_j(1≤uj,vj≤n, uj≠vj1 \le u_j, v_j \le n,\ u_j \neq v_j;1≤lowj≤wj≤1091 \le \mathrm{low}_j \le w_j \le 10^9)——表示第 jj 条边的两个端点及其属性。

该图不保证连通,且可能包含重边。

保证所有测试用例中 nn 的总和与 mm 的总和均不超过 5⋅1055\cdot 10^5。

输出格式

For each test case, output nn integers separated by spaces. The ii-th integer should be the maximum score achievable starting from vertex ii, or −1-1 if no edge can be traversed.

对于每个测试用例,输出 nn 个由空格分隔的整数。其中第 ii 个整数应为从顶点 ii 出发所能获得的最大得分;若无法遍历任何一条边,则输出 −1-1。

输入输出样例

  • 输入#1

    9
    3 2
    10 20 5
    1 2 5 2
    2 3 4 3
    2 1
    100 10
    1 2 10 5
    2 0
    50 50
    1 0
    114514
    4 1
    1 2 3 4
    3 4 2 1
    3 2
    1 4 1
    1 3 4 1
    1 2 2 1
    3 2
    10 3 2
    2 3 4 4
    2 1 3 2
    3 2
    5 2 2
    3 2 4 4
    1 3 5 5
    5 9
    857147200 381798978 633421584 956726892 315899900
    2 1 883474754 795831571
    2 4 657281748 375466725
    1 3 666641114 444218918
    2 3 901861650 790895313
    3 2 613790652 96876004
    2 5 852725279 216601090
    3 4 500240642 193633892
    2 5 210434355 130646156
    3 2 457018372 279005896

    输出#1

    25 25 24
    110 110
    -1 -1
    -1
    -1 -1 6 6
    6 6 6
    13 13 7
    10 9 10
    1740621954 1740621954 1740621954 1614008640 1709872479

说明/提示

In the first test case, here are the optimal hstarth_{start} values and paths for each starting node:

  • For node 11, it is optimal to use hstart=5h_{start}=5. Then, take the path from node 11 to node 22. hh is updated to max⁡(5,2)=5\operatorname{max}(5,2)=5. The path ends, and the score is 20+5=2520+5=25.
  • For node 22, it is optimal to use hstart=5h_{start}=5. Then, take the path from node 22 to node 11, then from node 11 to node 22. The score is 20+5=2520+5=25.
  • For node 33, it is optimal to use hstart=4h_{start}=4. Then, take the path from node 33 to node 22. The score is 20+4=2420+4=24.

In the third test case, since there are no edges incident to either node, the answer is −1-1 for both.

在第一个测试用例中,每个起始节点对应的最优 hstarth_{start} 值及路径如下:

  • 对于节点 11,最优选择为 hstart=5h_{start}=5。然后沿节点 11 到节点 22 的路径行进,hh 更新为 max⁡(5,2)=5\operatorname{max}(5,2)=5。路径结束,得分为 20+5=2520+5=25。
  • 对于节点 22,最优选择为 hstart=5h_{start}=5。然后沿节点 22 到节点 11、再从节点 11 到节点 22 的路径行进。得分为 20+5=2520+5=25。
  • 对于节点 33,最优选择为 hstart=4h_{start}=4。然后沿节点 33 到节点 22 的路径行进。得分为 20+4=2420+4=24。

在第三个测试用例中,由于没有任何边与节点 11 或节点 22 关联,因此两者的答案均为 −1-1。

输入解题思路,AI测评打分。不知道怎么写?

首页