Pagini recente » Cod sursa (job #2208850) | Istoria paginii runda/moisil | Cod sursa (job #1781815) | Cod sursa (job #2899367) | Cod sursa (job #503570)
Cod sursa(job #503570)
#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;
}