#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
struct nond{
int x,y,z;
}edge[*];
int T,N,M,x,y,z,fa[],num,ans[];
int tot,bns,k,answer=;
int cmp(nond aa,nond bb){
return aa.z<bb.z;
}
int find(int x){
return fa[x]==x?x:fa[x]=find(fa[x]);
}
int main(){
cin>>T;
while(T--){
cin>>N>>M;
tot=;bns=;
answer=;
memset(fa,,sizeof(fa));
memset(ans,,sizeof(ans));
for(int i=;i<=M;i++){
cin>>x>>y>>z;
edge[i].x=x;
edge[i].y=y;
edge[i].z=z;
}
sort(edge+,edge++M,cmp);
for(int i=;i<=N;i++) fa[i]=i;
for(int i=;i<=M;i++){
int dx=find(edge[i].x),dy=find(edge[i].y);
if(dx!=dy){
fa[dx]=dy;
tot++;
ans[tot]=i;
bns+=edge[i].z;
}
if(tot==N-) break;
}
for(int i=;i<=tot;i++){
k=;num=;
for(int j=;j<=N;j++) fa[j]=j;
sort(edge+,edge++M,cmp);
for(int j=;j<=M;j++){
if(j==ans[i]) continue;
int dx=find(edge[j].x),dy=find(edge[j].y);
if(dx!=dy){
fa[dx]=dy;
num++;
k+=edge[j].z;
}
if(num==N-) break;
}
if(num==N-) answer=min(k,answer);
}
if(answer==bns) cout<<"Not Unique!"<<endl;
else cout<<bns<<endl;
}
}
 

K - The Unique MST的更多相关文章

  1. K - The Unique MST - poj 1679

    题目的意思已经说明了一切,次小生成树... ****************************************************************************** ...

  2. K - The Unique MST (最小生成树的唯一性)

    Given a connected undirected graph, tell if its minimum spanning tree is unique. Definition 1 (Spann ...

  3. The Unique MST (判断是否存在多个最小生成树)

    The Unique MST                                                                        Time Limit: 10 ...

  4. POJ 1679 The Unique MST (次小生成树kruskal算法)

    The Unique MST 时间限制: 10 Sec  内存限制: 128 MB提交: 25  解决: 10[提交][状态][讨论版] 题目描述 Given a connected undirect ...

  5. POJ1679:The Unique MST(最小生成树)

    The Unique MST Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 38430   Accepted: 14045 ...

  6. POJ 1679 The Unique MST 【最小生成树/次小生成树模板】

    The Unique MST Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 22668   Accepted: 8038 D ...

  7. POJ1679 The Unique MST —— 次小生成树

    题目链接:http://poj.org/problem?id=1679 The Unique MST Time Limit: 1000MS   Memory Limit: 10000K Total S ...

  8. POJ-1679.The Unique MST.(Prim求次小生成树)

    The Unique MST Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 39561   Accepted: 14444 ...

  9. POJ - 1679_The Unique MST

    The Unique MST Time Limit: 1000MS Memory Limit: 10000K Description Given a connected undirected grap ...

随机推荐

  1. android中LocalBroadcastManager的使用

    今天遇到一个acitivity之间通信的问题,因为我们是用TabActivity包裹了Activity(我们称之为A).所以这两个Activity是同一时候存在的.当在TabActivity中启动其它 ...

  2. oc14--匿名对象

    // // main.m // 匿名对象 #import <Foundation/Foundation.h> #import "Person.h" #import &q ...

  3. 循环神经网络(RNN, Recurrent Neural Networks)——无非引入了环,解决时间序列问题

    摘自:http://blog.csdn.net/heyongluoyao8/article/details/48636251 不同于传统的FNNs(Feed-forward Neural Networ ...

  4. 表格td内容过多时,td显示省略号,鼠标移入显示全部内容。

    转自:https://blog.csdn.net/weixin_42193908/article/details/80405014 两种方式显示: 1.title方式显示: <!DOCTYPE ...

  5. configparser (配置文件) 模块

    主要内容来自景女神博客 内涵:该模块适用于配置文件的格式与windows ini文件类似,可以包含一个或多个节(section),每个节可以有多个参数(键=值). 常见文档格式: [DEFAULT] ...

  6. 09.javaweb简单标签编程

    一.简单标签 1,  简介:由于传统标签使用三个标签接口来完成不同的功能,显得过于繁琐,不利于标签技术的推广, SUN公司为降低标签技术的学习难度,在JSP 2.0中定义了一个更为简单.便于编写和调用 ...

  7. hdu2680 Choose the best route 最短路(多源转单源)

    此题中起点有1000个,边有20000条.用链式前向星建图,再枚举起点用SPFA的话,超时了.(按理说,两千万的复杂度应该没超吧.不过一般说计算机计算速度 1~10 千万次/秒.也许拿最烂的计算机来卡 ...

  8. redis启动出错 Creating Server TCP listening socket 127.0.0.1:6379: bind: No error解决办法

    windows下安装Redis第一次启动报错: [2368] 21 Apr 02:57:05.611 # Creating Server TCP listening socket 127.0.0.1: ...

  9. 如何处理CSS3属性前缀(转载)总结

    今天闲来无聊,重新来说说CSS3前缀的问题.在春节前和@一丝姐姐说起Sass中有关于gradient的mixins.姐姐说: 为什么还要用mixin呢?为什么不使用Autoprefixer?使用Aut ...

  10. CentOS7环境RabbitMQ集群配置管理(转载)

    CentOS7环境RabbitMQ集群配置管理(转载)   CentOS7系统内核版本:3.10.0-514.26.2.el7.x86_64 一.对应主机host地址(三台主机host文件要保持一致) ...