Cod sursa(job #379101)

Utilizator GheorgheMihaiMihai Gheorghe GheorgheMihai Data 30 decembrie 2009 17:05:53
Problema PScNv Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.67 kb
#include<stdio.h>
#include<algorithm>
using namespace std;
struct vect
{
	int x,y,z;
};
int n,m,x,y,t[250002];
vect v[500002];

bool cmp(vect a, vect b)
{
	return a.z<b.z;
}

int find(int x)
{
	if(x!=t[x])
		t[x]=find(t[x]);
	return t[x];
}

int main()
{
	freopen("pscnv.in","r",stdin);
	freopen("pscnv.out","w",stdout);
	scanf("%d%d%d%d",&n,&m,&x,&y);
	int i;
	for(i=1;i<=m;i++)
		scanf("%d%d%d",&v[i].x,&v[i].y,&v[i].z);
	sort(v+1,v+m+1,cmp);
	for(i=1;i<=n;i++)
		t[i]=i;
	for(i=1;i<=m;i++)
	{
		if(find(v[i].x)!=find(v[i].y))
			t[t[v[i].x]]=t[v[i].y];
		if(find(x)==find(y))
		{
			printf("%d\n",v[i].z);
			break;
		}
	}
	return 0;
}