Cod sursa(job #333675)

Utilizator cezarbotolanbotolan cezar cezarbotolan Data 23 iulie 2009 15:23:54
Problema PScNv Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.31 kb
#include <cstdio>
#include <vector>
#include <algorithm>

using namespace std;

#define file_in "pscnv.in"
#define file_out "pscnv.out"

#define Nmax 259101
#define pb push_back


struct muchie
{
	int x,y,c;
};

vector < pair < int,int > > g[Nmax];

int n,m;
int t[Nmax];
int s,d;

int cmp(muchie x,muchie y)
{
    return x.c < y.c;
}


int tata(int x)
{
    int y=x,z,aux;
    while(y!=t[y])
        y=t[y];
    z=x;
    while(z!=t[z])
    {
        aux=t[z];
        t[z]=y;
        z=aux;
    }
    return y;
}


int main()
{
	int i,t1,t2;
	freopen(file_in,"r",stdin);
	freopen(file_out,"w",stdout);
	muchie xx;
	scanf("%d %d %d %d", &n,&m, &s,&d);
	for (i=0;i<m;++i)
	{
		scanf("%d %d %d", &xx.x,&xx.y,&xx.c);
		g[xx.c].pb(make_pair(xx.x,xx.y));
		
		//g.pb(xx);
		//g1[xx.c].pb(xx.x);
		//g2[xx.c].pb(xx.y);
        /*g1[xx.c]=xx.x;
		g2[xx.c]=xx.y;*/
	}
	vector < pair< int, int > > :: iterator it;
	for (i=1;i<=n;++i) t[i]=i;
	
	//sort(g.begin(),g.end(),cmp);
	
	for (i=1;i<=1000;++i)
	{
		/*for (i=0;i<m;++i)
		{*/
	for (it=g[i].begin();it!=g[i].end();++it)
	{
		t1=tata(it->first);
		t2=tata(it->second);
		if (t1!=t2)
			t[t1]=t2;
	}
		if (tata(s)==tata(d)) break;
	}
	
	printf("%d ",i);
	
	fclose(stdin);
	fclose(stdout);
	
	return 0;
}