#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. ios设计一部WindowsPhone手机

    ios设计一部WindowsPhone手机 main.m #import <Foundation/Foundation.h> #import "WindowsPhone.h&qu ...

  2. 弗拉特利定律:Illumina怎样缔造基因革命

    蕾妮·瓦林特(Renee Valint)的女儿谢尔碧(Shelby)在2000年出生时.看起来虚弱无力,就如同一仅仅耷拉着的布娃娃.谢尔碧学着走路和说话,但学得很慢.错过了儿童发展的重要阶段.到4岁时 ...

  3. c27---typedef

    // // main.c // typedef #include <stdio.h> /* typedef可以给一个已知的数据类型起别名. typedef 原有的数据类型 别名; 注意: ...

  4. Hyper和Vmware冲突,Device/Credential Guard 不兼容

    切换到VM的时候,采用关闭策略 1.PS管理员关闭命令 bcdedit /set hypervisorlaunchtype off 2.系统设置,启用或关闭Windows功能那里,关闭Hyper-V ...

  5. FZU2150 Fire Game

    题目: 两个熊孩子在n*m的平地上放火玩,#表示草,两个熊孩子分别选一个#格子点火,火可以向上向下向左向右在有草的格子蔓延,点火的地方时间为0,蔓延至下一格的时间依次加一.求烧完所有的草需要的最少时间 ...

  6. 【转】Java的可变类与不可变类

    1.可变类和不可变类(Mutable and Immutable Objects)的初步定义: 可变类:当你获得这个类的一个实例引用时,你可以改变这个实例的内容. 不可变类:当你获得这个类的一个实例引 ...

  7. css3 边框、背景、文本效果

    浅玩CSS3 边框.背景.文本效果 一.边框 box-shadow box-shadow: h-shadow v-shadow blur spread color inset(ontset); //h ...

  8. JavaScript函数传参

    函数传参一: <html> <head> <meta charset="utf-8"> <title>无标题文档</title ...

  9. 读<<大数据时代>>的一些感想

    第一次听说<<大数据时代>>这本书,是在网上看到的央视搞的一个2013中国好书评选活动推荐的25本“中国好书”的榜单中看到的.然后迅速上豆瓣上查看了一下对该书的评价,一看非常高 ...

  10. 用Navicat自动备份mysql数据库

    以下文章转载自https://blog.csdn.net/u013628152/article/details/54909885,放在自己的博客园以供后面方便查询 —————————————————— ...