Cod sursa(job #3276948)

Utilizator zavragiudavid dragoi zavragiu Data 15 februarie 2025 10:38:16
Problema Radiatie Scor 30
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.31 kb
#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;
}