Cod sursa(job #1025580)

Utilizator dumitrualexAlex Dumitru dumitrualex Data 10 noiembrie 2013 11:55:50
Problema Radiatie Scor 30
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.29 kb
#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];

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;
                    coada.push(u[p][i].dest);
                }
            }
    }
}

int main()
{
    int x, y, c;
    fin >> n >> m >> k;
    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;
        dijkstra(x);
        fout << pas[y] << '\n';
    }
    return 0;
}