Pagini recente » Cod sursa (job #916825) | Cod sursa (job #289895) | Cod sursa (job #192946) | Cod sursa (job #2726652) | Cod sursa (job #1025581)
#include <fstream>
#include <vector>
#include <queue>
#define FOR(i, a, b) for(int i = (a); i <= (b); i++)
#define nmax 15000+5
#define inf 1 << 30
using namespace std;
ifstream fin("radiatie.in");
ofstream fout("radiatie.out");
struct muchie
{
int dest;
int cost;
muchie(int dest = 0, int cost = 0) : dest(dest), cost(cost)
{
}
};
int n, m, k;
vector<muchie> u[nmax];
queue<int> coada;
int pas[nmax];
int memo[nmax][nmax];
void dijkstra(int vf)
{
int p, t;
FOR(i, 1, n)
pas[i] = inf;
coada.push(vf);
pas[vf] = 0;
while (!coada.empty())
{
p = coada.front();
coada.pop();
if (!u[p].empty())
FOR(i, 0, u[p].size()-1)
{
t = max(pas[p], u[p][i].cost);
if (t < pas[u[p][i].dest])
{
pas[u[p][i].dest] = t;
memo[vf][u[p][i].dest] = t;
coada.push(u[p][i].dest);
}
}
}
}
int main()
{
int x, y, c;
fin >> n >> m >> k;
FOR(i, 1, n)
FOR(j, 1, n)
memo[i][j] = -1;
FOR(i, 1, m)
{
fin >> x >> y >> c;
u[x].push_back(muchie(y, c));
u[y].push_back(muchie(x, c));
}
FOR(i, 1, k)
{
fin >> x >> y;
if (x > y)
swap(x, y);
if (memo[x][y] == -1)
dijkstra(x);
fout << memo[x][y] << '\n';
}
return 0;
}