Pagini recente » Cod sursa (job #1131215) | Cod sursa (job #1298460) | Cod sursa (job #781728) | Cod sursa (job #2336153) | Cod sursa (job #3276948)
#include <iostream>
#include <vector>
#include <algorithm>
#include <iostream>
#include <string>
#include <bitset>
#include <queue>
#include <fstream>
#include <stdio.h>
#include <string.h>
#include <iomanip>
#include <stack>
#include <climits>
#include <unordered_map>
#include <map>
#include <set>
#include <cmath>
using namespace std;
ifstream fin("radiatie.in");
ofstream fout("radiatie.out");
/*
1 2 3 4
*/
int m, n, k, dist[15002], mat[15002][15002];
vector<pair<int, int> > G[15002];
const int oo = 1e9;
queue<pair <int, int >> q;
void BFS(int x)
{
q.push({ x, 0 });
dist[x] = 0;
while (!q.empty())
{
auto t = q.front();
q.pop();
for(auto w : G[t.first])
if (dist[w.first] > max(t.second, w.second))
{
dist[w.first] = max(t.second, w.second);
q.push({ w.first, max(t.second, w.second) });
}
}
for (int i = 1; i <= n; i++)
mat[x][i] = mat[i][x] = dist[i];
}
int main()
{
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 });
}
for (i = 1; i <= n; i++)
for (j = 1; j <= n; j++)
mat[i][j] = oo;
while (k--)
{
for (i = 1; i <= n; i++)
dist[i] = oo;
fin >> i >> j;
if(mat[i][j] == oo) BFS(i);
fout << mat[i][j] << "\n";
}
return 0;
}