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 n vertices and m edges. The i-th vertex has an associated value vali. The j-th edge connects vertices uj and vj and has two properties: a capacity wj and a floor lowj. It is guaranteed that wj≥lowj for all edges.
You want to start a walk from a vertex s. Before the walk begins, you must choose an arbitrary non-negative integer hstart as your initial state parameter.
If you are currently at vertex u with state h, you can traverse an edge j connecting u and v if and only if wj≥h. Upon traversing this edge and arriving at vertex v, the state parameter h updates to max(h,lowj).
Let the walk end at some vertex t. You must traverse at least one edge. The score of such a walk is defined as valt+hstart. 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 s from 1 to n, calculate the maximum possible score achievable. If it is impossible to traverse any edge starting from some s, output −1 instead.
— Frums
给定一个包含 n 个顶点和 m 条边的无向图。第 i 个顶点关联一个值 vali。第 j 条边连接顶点 uj 和 vj,并具有两个属性:容量 wj 和下界 lowj。保证对所有边均有 wj≥lowj。
你希望从某个顶点 s 出发开始一次行走。在行走开始前,你必须任选一个非负整数 hstart 作为初始状态参数。
若当前位于顶点 u 且状态为 h,则当且仅当 wj≥h 时,你才能沿第 j 条边(连接 u 和 v)行进。当你经该边抵达顶点 v 后,状态参数 h 更新为 max(h,lowj)。
设该行走终止于某个顶点 t。你必须至少经过一条边。此类行走的得分定义为 valt+hstart。注意:我们关心的是终点顶点的值与初始状态参数之和,而非最终状态参数。
对每个起始顶点 s(从 1 到 n),计算所能达到的最大得分。若从某个 s 出发无法经过任何边,则输出 −1。
输入格式
Each test contains multiple test cases. The first line contains the number of test cases t (1≤t≤104). The description of the test cases follows.
The first line of each test case contains two integers n and m (1≤n≤5⋅105,0≤m≤5⋅105) — the number of vertices and the number of edges.
The second line of each test case contains n integers val1,val2,…,valn (1≤vali≤109) — the values of the vertices.
The next m lines describe the edges. The j-th line contains four integers uj,vj,wj,lowj (1≤uj,vj≤n,uj=vj; 1≤lowj≤wj≤109) — the endpoints and properties of the j-th edge.
The graph is not guaranteed to be connected and may contain multiple edges.
It is guaranteed that the sum of n and the sum of m over all test cases do not exceed 5⋅105.
每个测试包含多个测试用例。第一行包含测试用例数量 t(1≤t≤104)。随后是各测试用例的描述。
每个测试用例的第一行包含两个整数 n 和 m(1≤n≤5⋅105, 0≤m≤5⋅105)——分别表示顶点数和边数。
每个测试用例的第二行包含 n 个整数 val1,val2,…,valn(1≤vali≤109)——表示各顶点的权值。
接下来的 m 行描述边的信息。第 j 行包含四个整数 uj,vj,wj,lowj(1≤uj,vj≤n, uj=vj;1≤lowj≤wj≤109)——表示第 j 条边的两个端点及其属性。
该图不保证连通,且可能包含重边。
保证所有测试用例中 n 的总和与 m 的总和均不超过 5⋅105。
输出格式
For each test case, output n integers separated by spaces. The i-th integer should be the maximum score achievable starting from vertex i, or −1 if no edge can be traversed.
对于每个测试用例,输出 n 个由空格分隔的整数。其中第 i 个整数应为从顶点 i 出发所能获得的最大得分;若无法遍历任何一条边,则输出 −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 hstart values and paths for each starting node:
- For node 1, it is optimal to use hstart=5. Then, take the path from node 1 to node 2. h is updated to max(5,2)=5. The path ends, and the score is 20+5=25.
- For node 2, it is optimal to use hstart=5. Then, take the path from node 2 to node 1, then from node 1 to node 2. The score is 20+5=25.
- For node 3, it is optimal to use hstart=4. Then, take the path from node 3 to node 2. The score is 20+4=24.
In the third test case, since there are no edges incident to either node, the answer is −1 for both.
在第一个测试用例中,每个起始节点对应的最优 hstart 值及路径如下:
- 对于节点 1,最优选择为 hstart=5。然后沿节点 1 到节点 2 的路径行进,h 更新为 max(5,2)=5。路径结束,得分为 20+5=25。
- 对于节点 2,最优选择为 hstart=5。然后沿节点 2 到节点 1、再从节点 1 到节点 2 的路径行进。得分为 20+5=25。
- 对于节点 3,最优选择为 hstart=4。然后沿节点 3 到节点 2 的路径行进。得分为 20+4=24。
在第三个测试用例中,由于没有任何边与节点 1 或节点 2 关联,因此两者的答案均为 −1。
输入解题思路,AI测评打分。不知道怎么写?