POJ-1679 The Unique MST(サブツリー、最小生成ツリーが一意かどうか判断)
19226 ワード
http://poj.org/problem?id=1679
Description
Given a connected undirected graph,tell if its minimum spanning tree is unique.
Definition 1(Spanning Tree):Consder a connected、undirected graph G=(V,E).A spanning tree of G is a subgraphh of G,say T=(V',E')、with the following properties:
1.V'=V.
2.T is connected and acyclic.
Definition 2(Minimm Spanning Tree):Consder an edge-weighted、connected、undirected graph G=(V,E).The minimum spanning tree T=(V,E')of G is the spanning tree has the smas the smart the costits.s the costit。
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)、thenberginfollable.ingline。indicating that xi and yi are connected by an edge with weight=wi.For any two nodes,there ist one edge connecting them.
Output
For each input、if the MST is unique、print the total cost of it、or other wise prist 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 Output3
Not Unique!
件名:
n点mの辺に重さの辺がないことをあげて、最小の木が唯一かどうかを生成することを求めて、もしこの最小の生成樹は唯一だならば、最小の木の上の権利の和を出力して、唯一のはNot Uniqueを出力するのではありません!
考え方:
次の小さい木を求めて、最小の結果と同じではないです。
サブツリー:
最小生成ツリーの変化によって、「次の小さい」は変化が最小になることによって、ツリー上の1つの辺を生成するだけで実現され、この変化が最小になることが分かります。
素晴らしいブログを提供します。https://blog.csdn.net/qq_27437781/articale/detail/70821413
from:https://blog.csdn.net/u011721440/article/details/38735547
最小生成ツリーが一意かどうかを判断します。
1、図中の各辺に対して、他の辺をスキャンし、同じ値の辺があれば、その辺をマークする。
2、kruskyalまたはprimでMSTを求めます。
3、MSTにマークされたエッジがない場合、MSTは一意である。そうでなければ、MSTでマークのエッジを順次削除して、MSTを求めて、MSTの権利値と元のMSTの権利値が同じであれば、MSTは一意ではない。
from:https://blog.csdn.net/blue_skyrim/articale/detail/51338375
次の小さい木を生成するための求法は、エニュメレート・最小生成樹の各辺の一つを削除し、この二つの点に他の辺を見つけて、残りの辺は最小生成樹を形成する。
クァンビンのブログ:https://www.cnblogs.com/kuangbin/p/3147329.html
考え方:
最小生成ツリーを求める時、配列maxval[i][j]でMSTのiからjまでの最大辺権を表します。求め終わったら、直接エニュメレーションします。MSTの中にないすべての辺を、最大辺権を取り換えます。解答を更新します。注意点の番号は0から始まります。
原理:
最小生成ツリー上の隣接していない2点接続は必ず1つのリングになるので、これらの隣接していない点を列挙して彼らを接続させて、リングの中で最小生成ツリーの最大端に属するものを削除してもいいです。あるいは現在確定されている辺lowval[u],dpの思想です。これは木の構造を保証するだけでなく、木の変化を最小にすることができます。これらの列挙の中で一番小さい結果は次の小さい生成ツリーです。
1 #include
2 #include <string.h>
3 #include
4 #include <string>
5 #include
6 #include
7 #include
8 #include
9 #include
10 #include <set>
11 #include