CF609E.Minimum spanning tree for each edge

提高+/省选-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

Connected undirected weighted graph without self-loops and multiple edges is given. Graph contains n vertices and m edges.

For each edge (u, v) find the minimal possible weight of the spanning tree that contains the edge (u, v).

The weight of the spanning tree is the sum of weights of all edges included in spanning tree.

给定一个无向连通带权图,图中不含自环和重边。该图包含 nn 个顶点和 mm 条边。

对每条边 (u, v)(u,\,v),求包含该边 (u, v)(u,\,v) 的生成树的最小可能权重。

生成树的权重定义为其中所有边的权重之和。

输入格式

First line contains two integers n and m (1 ≤ n ≤ 2·105, n - 1 ≤ m ≤ 2·105) — the number of vertices and edges in graph.

Each of the next m lines contains three integers u__i, v__i, w__i (1 ≤ u__i, v__i ≤ n, u__i ≠ v__i, 1 ≤ w__i ≤ 109) — the endpoints of the i-th edge and its weight.

第一行包含两个整数 nn 和 mm(1≤n≤2⋅1051 \leq n \leq 2 \cdot 10^5,n−1≤m≤2⋅105n - 1 \leq m \leq 2 \cdot 10^5)—— 分别表示图中的顶点数和边数。

接下来的 mm 行中,每行包含三个整数 ui, vi, wiu_i,\, v_i,\, w_i(1≤ui, vi≤n1 \leq u_i,\, v_i \leq n,ui≠viu_i \neq v_i,1≤wi≤1091 \leq w_i \leq 10^9)—— 表示第 ii 条边的两个端点及其权重。

输出格式

Print m lines. i-th line should contain the minimal possible weight of the spanning tree that contains i-th edge.

The edges are numbered from 1 to m in order of their appearing in input.

输出 m 行。第 i 行应包含包含第 i 条边的生成树的最小可能权重。

边按其在输入中出现的顺序从 1 到 m 编号。

输入输出样例

  • 输入#1

    5 7
    1 2 3
    1 3 1
    1 4 5
    2 3 2
    2 5 3
    3 4 2
    4 5 4

    输出#1

    9
    8
    11
    8
    8
    8
    9

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

首页