22165_Second-bestminimumspanningtree

2022-5-16 18:21| 发布者: Hocassian| 查看: 23| 评论: 0|原作者: 肇庆学院ACM合集

摘要:
C:\Users\Administrator\Downloads\2019-10-12-10-14-5-89506166497000-Problem List-采集的数据-后羿采集器.html

Pro.ID

22165

Title

Second-best minimum spanning tree

Title链接

http://10.20.2.8/oj/exercise/problem?problem_id=22165

AC

0

Submit

0

Ratio

-

时间&空间限制

  • Time Limit: 2000/1000 MS (Java/Others)     Memory Limit: 65536/65536 K (Java/Others)
  • 描述

    Given a connected undirected graph with n vertexes and m edges with weights, I think it is easy for you to compute the minimum spanning tree. But what about the Second-best minimum spanning tree?

    In this problem, n is no more than m. And you can assume that all edge weights are distinct.

    The Second-best minimum spanning tree is defined as follows: let T denotes the set of all the spanning tree of G, T' denotes the minimum spanning tree of G, then T'' is the second-best minimum spanning tree of G such that weight(T'') = min{ weight( T''' ) | T'''T - T' }.

    输入

    For each test case, the first line contains two integer n, m ( 0 < n ≤ 100000, n ≤ m ≤ 1000000 ).

    Then there are m lines, each contains three integer x, y, w. It means that there is an edge between vertex x and vertex y with weight w ( 1 ≤ x, yn, 1 ≤ w ≤ 1000000 ). The test data ensure that the second-best minimum spanning tree do exist.

    输出

    Description

    Given a connected undirected graph with n vertexes and m edges with weights, I think it is easy for you to compute the minimum spanning tree. But what about the Second-best minimum spanning tree?

    In this problem, n is no more than m. And you can assume that all edge weights are distinct.

    The Second-best minimum spanning tree is defined as follows: let T denotes the set of all the spanning tree of G, T' denotes the minimum spanning tree of G, then T'' is the second-best minimum spanning tree of G such that weight(T'') = min{ weight( T''' ) | T'''T - T' }.

    Input

    For each test case, the first line contains two integer n, m ( 0 < n ≤ 100000, n ≤ m ≤ 1000000 ).

    Then there are m lines, each contains three integer x, y, w. It means that there is an edge between vertex x and vertex y with weight w ( 1 ≤ x, yn, 1 ≤ w ≤ 1000000 ). The test data ensure that the second-best minimum spanning tree do exist.

    Output

    For each test case, print the weight of the second-best minimum spanning tree in a single line.

    Sample Input

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

    Sample Output

    4
    7

    Source

    样例输入

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

    样例输出

    4
    7

    作者


    路过

    雷人

    握手

    鲜花

    鸡蛋

    最新评论

    返回顶部