Cod sursa(job #503570)

Utilizator skullLepadat Mihai-Alexandru skull Data 23 noiembrie 2010 19:30:41
Problema Radiatie Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.3 kb
#include <stdio.h>
#include <vector>
#include <algorithm>
#include <queue>
using namespace std;
#define punct pair<int,int>
#define nod first
#define cost second
#define nmax 15005
#define mmax 30005

int n, m, t, maxim;
int X[mmax], Y[mmax], C[mmax], ind[mmax], GR[nmax], viz[nmax];
int A[nmax][nmax];
vector<punct> G[nmax];

struct cmp
{
	bool operator () (const int &a, const int &b) const
	{
		return C[a] < C[b];
	}
};

void citire ()
{
	freopen("radiatie.in","r",stdin);
	scanf("%d %d %d ", &n, &m, &t);
	for (int i = 1; i <= m; ++i)
	{
		scanf("%d %d %d ", &X[i], &Y[i], &C[i]);
		ind[i] = i; GR[i] = i;
	}
}

int grupa (int x)
{
	if (GR[x] == x) return x;
	GR[x] = grupa(GR[x]);
	return GR[x];
}

void unire (int x, int y, int c)
{
	GR[grupa(x)] = grupa(y);
	G[x].push_back( make_pair(y,c));
	G[y].push_back( make_pair(x,c));
}

void kruskal ()
{
	sort(ind+1, ind+m+1, cmp() );
	for (int i = 1; i <= m; ++i)
		if ( grupa( X[ind[i]] ) != grupa( Y[ind[i]] ) )
			unire( X[ind[i]], Y[ind[i]], C[ind[i]]);
}

void drumuri ()
{
	freopen("radiatie.out","w",stdout);
	int i, x, y;
	aflamaxime ();
	for (i = 1; i <= t; ++i)
	{
		scanf("%d %d ", &x, &y);
		printf("%d\n", A[x][y]);
	}
}
	
int main ()
{
	citire ();
	kruskal ();
	drumuri ();
	return 0;
}