博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
POJ -1679(次小生成树)模板
阅读量:4579 次
发布时间:2019-06-09

本文共 2155 字,大约阅读时间需要 7 分钟。

The Unique MST
Time Limit: 1000MS   Memory Limit: 10000K
Total Submissions:34617   Accepted: 12637

Description

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

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

23 31 2 12 3 23 1 34 41 2 22 3 23 4 24 1 2

Sample Output

3Not Unique! 题意:求是否有第二个最小生成树 (次小生成树模板)
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
using namespace std;typedef long long ll;typedef unsigned int uint;typedef unsigned long long ull;const int maxn = 100 + 5;const int maxv = 10000 + 5;const int max_dis = 1e9 + 5;int T;int n,m;int a,b,c;int MST,_MST;bool vis[maxn];int father[maxn];int dist[maxn];int graph[maxn][maxn];bool used[maxn][maxn];int max_edge[maxn][maxn];void init() { memset(vis,false,sizeof(vis)); memset(used,false,sizeof(used)); memset(max_edge,-1,sizeof(max_edge)); memset(graph,0x7f,sizeof(graph));}void input() { scanf("%d%d",&n,&m); for(int i=0; i
View Code

 

转载于:https://www.cnblogs.com/buerdepepeqi/p/9105841.html

你可能感兴趣的文章
struts (一)
查看>>
【新番推荐】工作细胞
查看>>
NYOJ 16 矩形嵌套
查看>>
Leetcode中的SQL题目练习(二)
查看>>
dubbo 集群容错源码
查看>>
Collection接口的子接口——Queue接口
查看>>
LINUX安装NGINX
查看>>
服务器启动项目抛错 没有到主机的路由
查看>>
python_85_sys模块
查看>>
第九周动手动脑
查看>>
HDU 1811 Rank of Tetris
查看>>
winform 获取当前名称
查看>>
报表分栏后的排序
查看>>
Django中models定义的choices字典使用get_FooName_display()在页面中显示值
查看>>
nohup命令详解(转)
查看>>
别人的Linux私房菜(1)计算机概论
查看>>
系统编程之文件操作
查看>>
ModelState.IsValid
查看>>
菜鸟之路——机器学习之线性回归个人理解及Python实现
查看>>
opengl glut vs2013配置
查看>>