POJ 1679 次小生成树

题目大意,t组样例输入,n个点m条边,求除最小生成树以外的最短边。

暴力,可劲暴力,数据水,暴力出奇迹

模拟不选每条最小生成树中的边,取最小

代码

By Acer.Mo
#include
#include
#include
#include
#include
#include
#include
using namespace std;
struct edge
{
	int to;
	int from;
	int cost;
	bool friend operator < (edge a,edge b)
	{
		return a.cost>b.cost;	
	}	
}g[10000];
int sortt[10000],soid=0;
int n,m;
int father[10000];
int find(int x)
{
	if (x!=father[x]) father[x]=find(father[x]);
	return father[x];
}
void unionn(int a,int b)
{
	father[b]=a;
	return ;
} 
void constt()
{
	for (int i=1;i<=n;i++)
	{
		father[i]=i;
	}
}
int Kul()
{
	int ans=0,tot=1;
	for (int i=1;i<=m;i++)
	{
		int r1=find(g[i].from);
		int r2=find(g[i].to);
		if (r1!=r2)
		{
			tot++;
			unionn(r1,r2);
			ans+=g[i].cost;
			sortt[soid++]=i;
			if (tot==n) break;
		}
	}
	if (tot


你可能感兴趣的:(图论-最小生成树)