POJ1679 Luogu4180 次小生成树
The Unique MST
Given a connected undirected graph, tell if its minimum spanning tree is unique.
Definition 1 (Spanning Tree): Consider a connected, undirected graph G = (V, E). A spanning tree of G is a subgraph of G, say T = (V’, E’), with the following properties:
Definition 2 (Minimum Spanning Tree): Consider an edge-weighted, connected, undirected graph G = (V, E). The minimum spanning tree T = (V, E’) of G is the spanning tree that has the smallest total cost. The total cost of T means the sum of the weights on all the edges in E’.
Input
The first line contains a single integer t (1 <= t <= 20), the number of test cases. Each case represents a graph. It begins with a line containing two integers n and m (1 <= n <= 100), the number of nodes and edges. Each of the following m lines contains a triple (xi, yi, wi), indicating that xi and yi are connected by an edge with weight = wi. For any two nodes, there is at most one edge connecting them.
Output
For each input, if the MST is unique, print the total cost of it, or otherwise print the string ‘Not Unique!’.
Sample Input
2
3 3
1 2 1
2 3 2
3 1 3
4 4
1 2 2
2 3 2
3 4 2
4 1 2
Sample Output
3
Not Unique!
算法過程:
先求出最小生成樹,然后枚舉每一條不再最小生成樹上的邊,并把這條邊放到最小生成樹上面,那么我們在這條環路上取出一條最長的路,處理新加入的那一條邊,最終得到的權值就是最小生成樹的權值
總結
以上是生活随笔為你收集整理的POJ1679 Luogu4180 次小生成树的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 2018 焦作站亚洲区域赛校内选拔赛题解
- 下一篇: 牛客网 New Game! 建图+最短路