CF827D.Best Edge Weight

省选/NOI-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

You are given a connected weighted graph with n vertices and m edges. The graph doesn't contain loops nor multiple edges. Consider some edge with id i. Let's determine for this edge the maximum integer weight we can give to it so that it is contained in all minimum spanning trees of the graph if we don't change the other weights.

You are to determine this maximum weight described above for each edge. You should calculate the answer for each edge independently, it means there can't be two edges with changed weights at the same time.

给你一个包含 nn 个顶点和 mm 条边的连通带权图。该图不含自环或重边。考虑某条编号为 ii 的边。请确定:在不改变其余所有边权重的前提下,该边所能被赋予的最大整数权重,使得它必然出现在图的所有最小生成树中。

你需要对每条边分别计算上述最大权重。注意:每条边的答案需独立计算,即任意时刻至多只允许一条边的权重被修改。

输入格式

The first line contains two integers n and m (2 ≤ n ≤ 2·105, n - 1 ≤ m ≤ 2·105), where n and m are the number of vertices and the number of edges in the graph, respectively.

Each of the next m lines contains three integers u, v and c (1 ≤ v, u ≤ n, v ≠ u, 1 ≤ c ≤ 109) meaning that there is an edge between vertices u and v with weight c.

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

接下来的 mm 行,每行包含三个整数 uu、vv 和 cc(1≤u,v≤n1 \leq u, v \leq n,u≠vu \neq v,1≤c≤1091 \leq c \leq 10^9),表示顶点 uu 与顶点 vv 之间存在一条权重为 cc 的边。

输出格式

Print the answer for each edge in the order the edges are given in the input. If an edge is contained in every minimum spanning tree with any weight, print -1 as the answer.

按输入中给出边的顺序,为每条边输出答案。如果某条边在任意权值下都属于每一棵最小生成树,则输出 -1 作为该边的答案。

输入输出样例

  • 输入#1

    4 4
    1 2 2
    2 3 2
    3 4 2
    4 1 3

    输出#1

    2 2 2 1
  • 输入#2

    4 3
    1 2 2
    2 3 2
    3 4 2

    输出#2

    -1 -1 -1

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

首页