Pagini recente » Cod sursa (job #779977) | Cod sursa (job #279502) | Cod sursa (job #840770) | Cod sursa (job #1819169) | Cod sursa (job #3277205)
#include<bits/stdc++.h>
using namespace std;
ifstream fin("radiatie.in");
ofstream fout("radiatie.out");
vector< pair<int,int> > G[100005];
queue<int> q;
int n,m,k, d[100005];
void BFS(int x)
{
int t;
d[x] = 0;
q.push(x);
while(!q.empty())
{
t = q.front();
q.pop();
for(auto e : G[t])
if(d[e.first] > max(d[t], e.second))
{
d[e.first] = max(d[t], e.second);
q.push(e.first);
}
}
}
int main()
{
ios::sync_with_stdio(0);
fin.tie(0);
fout.tie(0);
int i,j,c;
fin >> n >> m >> k;
while(m--)
{
fin >> i >> j >> c;
G[i].push_back({j,c});
G[j].push_back({i,c});
}
while(k--)
{
for(int p = 1; p <= n; p++)
d[p] = 1e10;
fin >> i >> j;
BFS(i);
fout << d[j] << "\n";
}
return 0;
}