Pagini recente » Cod sursa (job #2456669) | Cod sursa (job #1204946) | Rating Ciuchilan Bianca (Ciuchilan_Bianca) | Cod sursa (job #1160947) | Cod sursa (job #1507397)
#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[250002];
int n, d[250002], X, Y;
/// d[i]= costul minim al unei muchii de pe drumul de la
/// nodul de start X la nodul i
void Citire()
{
char s[100];
int v[3], p;
int x, i, m, j;
Nod w;
ifstream fin(inFile);
fin >> n >> m >> X >> Y;
fin.get();
for (i = 1; i <= m; ++i)
{
fin.getline(s,99);
p = 0; x = 0;
for (j = 0; s[j]; j++)
if (s[j] != ' ') x = x * 10 + (s[j] - '0');
else
{
if (x != 0) v[p++] = x;
x = 0;
}
if (x != 0) v[p] = x;
x = v[0];
w.nod = v[1];
w.cost = v[2];
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;
}