Cod sursa(job #3277205)

Utilizator mateistefan11matei stefan mateistefan11 Data 15 februarie 2025 13:41:05
Problema Radiatie Scor 30
Compilator cpp-64 Status done
Runda vs11_12_vine_oji_2025 Marime 0.93 kb
#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;
}