Pagini recente » Cod sursa (job #2203866) | Cod sursa (job #2943212) | Cod sursa (job #2928658) | Cod sursa (job #962804) | Cod sursa (job #1507375)
#include <bits/stdc++.h>
#define inFile "pscnv.in"
#define outFile "pscnv.out"
using namespace std;
struct Nod
{
int nod, cost;
bool operator < (const Nod& e) const
{
return cost > e.cost;
}
};
vector <Nod> h[36002];
int n, d[36002], X, Y;
/// d[i]= costul minim al unei muchii de pe drumul de la
/// nodul de start X la nodul i
void Citire()
{
int x, y, c, i, m;
Nod w;
ifstream fin(inFile);
fin >> n >> m >> X >> Y;
for (i = 1; i <= m; ++i)
{
fin >> x >> y >> c;
w.nod = y;
w.cost = c;
h[x].push_back(w);
}
fin.close();
}
void Dijkstra()
{
priority_queue<Nod> q;
Nod w, w1;
int i, k, c, cost;
unsigned int j;
for (i = 1; i <= n; i++)
d[i] = 1000000000;
d[X] = 0;
w.nod = X;
w.cost = 0;
q.push(w);
while (!q.empty())
{
w = q.top();
q.pop();
k = w.nod;
for (j = 0; j < h[k].size(); j++)
{
i = h[k][j].nod;
c = h[k][j].cost;
cost = max(d[k], c);
if (d[i] > cost)
{
d[i] = cost;
w1.nod = i;
w1.cost = cost;
q.push(w1);
}
}
}
}
void Afisare()
{
ofstream fout(outFile);
fout << d[Y] << "\n";
fout.close();
}
int main()
{
Citire();
Dijkstra();
Afisare();
return 0;
}