#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. 理解和配置 Linux 下的 OOM Killer【转】

    本文转载自:http://www.vpsee.com/2013/10/how-to-configure-the-linux-oom-killer/ 最近有位 VPS 客户抱怨 MySQL 无缘无故挂掉 ...

  2. hdoj---Rescue

    Rescue Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 65536/32768K (Java/Other) Total Submis ...

  3. 部署微信定位精灵APK到Genymotion

  4. js设计模式-适配器模式

    说明:适配器模式表面上看起来像门面模式.它们都要对别的对象进行包装并改变其呈现的接口.但是两者的差别在于它们如何改变接口.门面元素展现的是一个简化的接口,它并不提供额外的选择,而且有时为了方便完成常见 ...

  5. BZOJ 3522 DFS+DP

    思路: f[]表示选1个点的 g[]表示选2个点的 dp一下 ans+=(ll)g[k]*deep[k]; g[k]+=(ll)f[k]*deep[k]; f[k]+=deep[k]; 听说有O(n) ...

  6. 修改Myeclipse中项目在tomcat上发布的名称

    1.从网上找的,但是没有用 2.直接修改工作空间中的文件

  7. Web移动端常见问题

    一.按钮点击时出现黑色背景 解决方法: .class { -webkit-tap-highlight-color:rgba(0,0,0,0);} .class { -webkit-appearance ...

  8. ubuntu+win10双系统,调整分区大小后进入了emergency mode

    问题背景: 装了Ubuntu+win10双系统,在Ubuntu下面挂载了Windows的D盘.后来因为D空间不够,进入Windows压缩C盘分区,扩大了D盘.重启后无法启动Ubuntu,进入了emer ...

  9. JVM上的下一个Java——Scala

    Scala是一种针对 JVM 将函数和面向对象技术组合在一起的编程语言.Scala编程语言近来抓住了很多开发者的眼球.它看起来像是一种纯粹的面向对象编程语言,而又无缝地结合了命令式和函数式的编程风格. ...

  10. 3D特征:关于HFM和HBB

    1.HBB    三维绑定框 (1): 要用到HBB,定义还不太清楚,来自于 VALVE Developer Community (https://developer.valvesoftware.co ...