当前你的浏览器版本过低,网站已在兼容模式下运行,兼容模式仅提供最小功能支持,网站样式可能显示不正常。
请尽快升级浏览器以体验网站在线编辑、在线运行等功能。

建议使用的浏览器:

谷歌Chrome 火狐Firefox Opera浏览器 微软Edge浏览器 QQ浏览器 360浏览器 傲游浏览器

6990:Directed Minimum Spanning Tree

题目描述
Yukikaze is studying graph theory. She is fascinated by an interesting combinatorial optimization problem, called the Directed Minimum Spanning Tree Problem.

A subgraph $T$ of a directed graph $G=(V,E)$ is called a Spanning Tree rooted at $r$ if for every vertex $v$ in $V-\{r\}$, there is exactly one path in $T$ from $r$ to $v$. The weight of a Spanning Tree is the sum of the weights of its edges. The Directed Minimum Spanning Tree (DMST) rooted at $r$ is the Spanning Tree rooted at $r$ which has the minimal weight.

For every vertex $u$ in the given graph, Yukikaze wants you to find the weight of the Directed Minimum Spanning Tree rooted at vertex $u$.
输入解释
The input consists of several test cases. The first line of the input contains a single integer $T$ $(1 \leq T \leq 3000)$, denoting the number of test cases.

For each test case, the first line contains two integers $n$ $(1 \leq n \leq 10^5)$ and $m$ $(1 \leq m \leq 2 \times 10^5)$, denoting the number of vertices and the number of edges in the graph.

Each of the next $m$ lines contains three integers $u_i,v_i,w_i\ (1 \leq u_i, v_i \leq n, 1 \leq w_i \leq 10^9)$, denoting the source, the target and the weight of the $i$-th edge. Please note that the edges are directed.

Let $S_n$ and $S_m$ be the sum of $n$ and the sum of $m$ in the input respectively. It is guaranteed that $1 \leq S_n \leq 5 \times 10^5$ and $1 \leq S_m \leq 10^6$.
输出解释
For each test case, output $n$ lines. The $i$-th line should contain the weight of the Directed Minimum Spanning Tree rooted at vertex $i$. If such DMST doesn't exist, output $-1$.
输入样例
2
5 6
1 2 5
2 3 6
3 1 7
1 4 3
4 5 4
5 1 2
6 8
1 4 1
2 5 7
4 3 4
5 6 12
6 2 9
3 5 10
3 1 23
4 2 17
输出样例
18
20
19
17
16
36
-1
55
58
-1
-1

该题目是Virtual Judge题目,来自 杭电HDUOJ

源链接: HDU-6990

最后修改于 2021-10-23T19:10:55+00:00 由爬虫自动更新

共提交 0

通过率 --%
时间上限 内存上限
12000/6000MS(Java/Others) 262144/262144K(Java/Others)