【UVA1395】UKE求助
查看原帖
【UVA1395】UKE求助
481330
sunyizhe还是MC大佬楼主2022/12/11 10:59

本人已经绑定了UVA账号。但交的时候总是UKE。

错误信息:

UnexpectedResponse: got an unexpected response when requesting `https://onlinejudge.org`: unable to find `cbsecuritym3`

代码:

#include <bits/stdc++.h>
using namespace std;
const int N=110,M=10010;
int p[N],rk[N],n,m,ans;
inline void make_set(int x)
{
	p[x]=x;
	rk[x]=1;
}
int find(int x)
{
	if(x!=p[x])p[x]=find(p[x]);
	return p[x];
}
int union_set(int x,int y)
{
	if(rk[x]<rk[y])swap(x,y);
	p[y]=x;
	if(rk[x]==rk[y])rk[x]++;
	return x;
}
struct Edge{
	int u,v,w;
	bool operator < (const Edge& rhs) const {
		return w<rhs.w;
	}
}e[M];
int weight;
bool kruskal(int edge)
{
	sort(e+1,e+m+1);
	for(int i=1;i<=n;i++)make_set(i);
	int cnt=0;
	for(int i=edge;i<=m;i++)
	{
		int x=find(e[i].u),y=find(e[i].v);
		if(x!=y)
		{
			union_set(x,y);
			weight=e[i].w;
			if(++cnt==n-1)return true;
		}
	}
	return false;
}
int main()
{
	while(scanf("%d %d",&n,&m)==2&&(n||m))
	{
		for(int i=1;i<=m;i++)scanf("%d %d %d",&e[i].u,&e[i].v,&e[i].w);
		ans=0x3f3f3f3f;
		for(int i=1;i<=m;i++)
			if(kruskal(i))ans=min(ans,weight-e[i].w);
		printf("%d\n",ans!=0x3f3f3f3f?ans:-1);
	}
	return 0;
}

有没有解决方案?

2022/12/11 10:59
加载中...