「POJ1679 」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:
1. V‘ = V.
2. T is connected and acyclic.

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‘.

输入格式

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.

输出格式

For each input, if the MST is unique, print the total cost of it, or otherwise print the string ‘Not Unique!‘.

样例输入

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

样例输出e

3
Not Unique!

题目大意

  • 给出一个有 n 个结点,m 条边的无向图,判断其最小生成树是否唯一。若唯一输出结果,不唯一输出“Not Unique!”

解题思路

  • 我们考虑MST 什么时候唯一?显然当加入一条非树边时MST会形成环。
  • 因此找到环上除了新加入的边外权值最大的边。当该边权值小于这条非树边,则MST唯一。
  • 因此先利用Kruskal算法求出最小生成树结果,再将形成最小生成树的路径进行标记,每次去掉一个最小生成树的边,用其他边代替,若能找到最小生成树的结果还为原本结果,即说明最小生成树不唯一。

原文地址:https://www.cnblogs.com/Yuns/p/10386481.html

时间: 2024-08-05 18:56:40

「POJ1679 」The Unique MST的相关文章

【POJ1679】The Unique MST

1 //ver1: Kruskal+暴力枚举删除边 2 #include<iostream> 3 #include<cstdio> 4 #include<algorithm> 5 using namespace std; 6 int t,n,m,first; 7 int a,ok,minx,p[101]; 8 struct edge{ 9 int v1,v2,d,v; //v标记MST中的每一条边 10 }e[10001]; 11 int findp(int x){ 1

POJ1679 The Unique MST 【次小生成树】

The Unique MST Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 20421   Accepted: 7183 Description Given a connected undirected graph, tell if its minimum spanning tree is unique. Definition 1 (Spanning Tree): Consider a connected, undire

poj1679 The Unique MST

题目大意:给定一个联无向网,判断它的最小生成树是否唯一. The Unique MST Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 20421 Accepted: 7183 Description Given a connected undirected graph, tell if its minimum spanning tree is unique. Definition 1 (Spanning Tree): Con

POJ1679 The Unique MST【Kruskal】【次小生成树】

The Unique MST Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 21304 Accepted: 7537 Description Given a connected undirected graph, tell if its minimum spanning tree is unique. Definition 1 (Spanning Tree): Consider a connected, undirected

POJ1679 The Unique MST(Kruskal)(最小生成树的唯一性)

The Unique MST Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 27141   Accepted: 9712 Description Given a connected undirected graph, tell if its minimum spanning tree is unique. Definition 1 (Spanning Tree): Consider a connected, undire

「题解」kuangbin 最小生成树

POJ-1251 Jungle Roads (水题,%c) POJ-1287 Networking (水) POJ-2031 Building a Space Station (%f浮点数尴尬精度,两球间距离) POJ-2421 Constructing Roads (一些边已建好,简单处理一下) ZOJ-1586 QS Network (处理一下边权) HDU-1233 还是畅通工程 (水) HDU-1875 畅通工程再续 (浮点数,条件连边) HDU-1301 Jungle Roads (重

AC日记——「HNOI2017」单旋 LiBreOJ 2018

#2018. 「HNOI2017」单旋 思路: set+线段树: 代码: #include <bits/stdc++.h> using namespace std; #define maxn 100005 #define maxtree maxn<<2 int val[maxtree],tag[maxtree],L[maxtree],R[maxtree],mid[maxtree]; int op[maxn],ki[maxn],bi[maxn],cnt,size,n,ch[maxn]

非关系型数据库中的「关系」实现

Knowledge Dependence:阅读文本前,你需要了解基本的关系型数据库与非关系型(NoSQL)数据库的概念和区别,以及 MongoDB(Mongoose)的简单实践. ? 这两三年来,伴随着大数据(Big Data)的空前火热,无论是在工程界还是科研界,非关系型数据库(NoSQL)都已经成为了一个热门话题. 相比于传统的关系型数据库,非关系型数据库天生从理念上就给数据存储提供了一种新的思路.而在实际应用中,它往往更轻巧灵活.扩展性高,并且更能胜任高性能.大数据量的场景. 值得一提的是

LibreOJ #2007. 「SCOI2015」国旗计划

二次联通门 : LibreOJ #2007. 「SCOI2015」国旗计划 --by Claris /* LibreOJ #2007. 「SCOI2015」国旗计划 跪膜Claris... */ #include <cstdio> #include <iostream> #include <algorithm> const int BUF = 12312312; char Buf[BUF], *buf = Buf; inline void read (int &