世界的终结,AI (CI翻译)
……以及那个穿越月之海洋的女孩。 — FrumsAI (CI翻译)
You are given an undirected graph consisting of $n$ vertices and $m$ edges. The $i$-th vertex has an associated value $\mathrm{val}_i$. The $j$-th edge connects vertices $u_j$ and $v_j$ and has two properties: a capacity $w_j$ and a floor $\mathrm{low}_j$. It is guaranteed that $w_j \ge \mathrm{low}_j$ for all edges.
给定一个由 $n$ 个顶点和 $m$ 条边组成的无向图。第 $i$ 个顶点有一个关联值 $\mathrm{val}_i$。第 $j$ 条边连接顶点 $u_j$ 和 $v_j$,并具有两个属性:容量 $w_j$ 和下限 $\mathrm{low}_j$。保证对所有边都有 $w_j \ge \mathrm{low}_j$。AI (CI翻译)
You want to start a walk from a vertex $s$. Before the walk begins, you must choose an arbitrary non-negative integer $h_{start}$ as your initial state parameter.
你想从顶点 $s$ 开始进行一段行走。在行走开始前,你必须选择一个任意的非负整数 $h_{start}$ 作为初始状态参数。AI (CI翻译)
If you are currently at vertex $u$ with state $h$, you can traverse an edge $j$ connecting $u$ and $v$ if and only if $w_j \ge h$. Upon traversing this edge and arriving at vertex $v$, the state parameter $h$ updates to $\max(h, \mathrm{low}_j)$.
若你当前位于顶点 $u$,状态为 $h$,当且仅当 $w_j \ge h$ 时,才能经过一条连接 $u$ 和 $v$ 的边 $j$。经过这条边并到达顶点 $v$ 后,状态参数 $h$ 更新为 $\max(h, \mathrm{low}_j)$。AI (CI翻译)
Let the walk end at some vertex $t$. You must traverse at least one edge. The score of such a walk is defined as $\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.
设行走结束于某个顶点 $t$。你必须至少经过 一条边。这段行走的 得分 定义为 $\mathrm{val}_t + h_{start}$。注意,我们关注的是最终顶点的值与初始状态参数之和,而不是最终状态参数。AI (CI翻译)
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.
对于每个起点 $s$(从 $1$ 到 $n$),计算能够取得的最大得分。如果从某个 $s$ 出发无法经过任何边,则输出 $-1$。AI (CI翻译)
Input
输入格式
AI (CI翻译)Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 10^4$). The description of the test cases follows.
每个输入包含多组测试用例。第一行包含测试用例数 $t$($1 \le t \le 10^4$)。随后是各测试用例的描述。AI (CI翻译)
The first line of each test case contains two integers $n$ and $m$ ($1 \le n \le 5\cdot 10^5, 0 \le m \le 5\cdot 10^5$) — the number of vertices and the number of edges.
每个测试用例的第一行包含两个整数 $n$ 和 $m$($1 \le n \le 5\cdot 10^5, 0 \le m \le 5\cdot 10^5$),分别表示顶点数和边数。AI (CI翻译)
The second line of each test case contains $n$ integers $\mathrm{val}_1, \mathrm{val}_2, \ldots, \mathrm{val}_n$ ($1 \le \mathrm{val}_i \le 10^9$) — the values of the vertices.
每个测试用例的第二行包含 $n$ 个整数 $\mathrm{val}_1, \mathrm{val}_2, \ldots, \mathrm{val}_n$($1 \le \mathrm{val}_i \le 10^9$),表示各顶点的值。AI (CI翻译)
The next $m$ lines describe the edges. The $j$-th line contains four integers $u_j, v_j, w_j, \mathrm{low}_j$ ($1 \le u_j, v_j \le n, u_j \neq v_j$; $1 \le \mathrm{low}_j \le w_j \le 10^9$) — the endpoints and properties of the $j$-th edge.
接下来的 $m$ 行描述各条边。第 $j$ 行包含四个整数 $u_j, v_j, w_j, \mathrm{low}_j$($1 \le u_j, v_j \le n, u_j \neq v_j$;$1 \le \mathrm{low}_j \le w_j \le 10^9$),表示第 $j$ 条边的端点及其属性。AI (CI翻译)
The graph is not guaranteed to be connected and may contain multiple edges.
图不一定连通,且可能包含重边。AI (CI翻译)
It is guaranteed that the sum of $n$ and the sum of $m$ over all test cases do not exceed $5\cdot 10^5$.
保证所有测试用例的 $n$ 之和与 $m$ 之和均不超过 $5\cdot 10^5$。AI (CI翻译)
Output
输出格式
AI (CI翻译)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$。AI (CI翻译)
Note
说明
AI (CI翻译)In the first test case, here are the optimal $h_{start}$ values and paths for each starting node:
在第一个测试用例中,各起点对应的最优 $h_{start}$ 和路径如下:AI (CI翻译)
- For node
$1$, it is optimal to use$h_{start}=5$. Then, take the path from node$1$to node$2$.$h$is updated to$\operatorname{max}(5,2)=5$. The path ends, and the score is$20+5=25$. - For node
$2$, it is optimal to use$h_{start}=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$h_{start}=4$. Then, take the path from node$3$to node$2$. The score is$20+4=24$.
- 对于顶点
$1$,最优选择是$h_{start}=5$。接着沿路径从顶点$1$到顶点$2$。此时$h$更新为$\operatorname{max}(5,2)=5$。行走结束,得分为$20+5=25$。 - 对于顶点
$2$,最优选择是$h_{start}=5$。接着沿路径从顶点$2$到顶点$1$,再从顶点$1$到顶点$2$。得分为$20+5=25$。 - 对于顶点
$3$,最优选择是$h_{start}=4$。接着沿路径从顶点$3$到顶点$2$。得分为$20+4=24$。
In the third test case, since there are no edges incident to either node, the answer is $-1$ for both.
在第三个测试用例中,由于两个顶点都没有相邻边,因此它们的答案均为 $-1$。AI (CI翻译)
样例
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
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
题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(gpt-6.1-sol),如有出入请以原文为准。