# Poj1679 the unique mst

## 判断最小生成树唯一性

Posted by yjjr's blog on March 11, 2019

# Code

#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define dep(i,a,b) for(int i=a;i>=b;i--)
#define mem(x,num) memset(x,num,sizeof x)
#define ll long long
#define reg(x) for(int i=last[x];i;i=e[i].next)
using namespace std;
ll f=1,x=0;char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
return x*f;
}
const int maxn=2e5+6;
int fa[maxn],n,m,T,sta[maxn],top=0;
struct edge{int u,v,w;}s[maxn];
inline int find(int x){return fa[x]==x?fa[x]:fa[x]=find(fa[x]);}
inline bool cmp(edge a,edge b){return a.w<b.w;}
inline int kruskal(int flag){
int num=0,sum=0,tot=0;
rep(i,1,m){
if(i==flag)continue;
int r1=find(s[i].u),r2=find(s[i].v);
if(r1!=r2){
fa[r1]=r2;sum+=s[i].w;num++;
if(flag==-1)sta[++top]=i;
}
if(num==n-1)break;
}
rep(i,1,n)if(fa[i]==i)tot++;
if(tot>1)return -1;
return sum;
}
int main(){
rep(TT,1,T){
mem(s,0);mem(sta,0);top=0;
rep(i,0,n+1)fa[i]=i;