Pagini recente » Cod sursa (job #2680928) | Cod sursa (job #890453) | Cod sursa (job #1702349) | Cod sursa (job #584681) | Cod sursa (job #949489)
Cod sursa(job #949489)
// solutia 1 - Dijkstra modificat
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <cstring>
#define dim 8192
using namespace std;
const char iname[] = "pscnv.in";
const char oname[] = "pscnv.out";
int d[250004], d2[250004];
struct nod{
int y, c; nod(){}; nod(int m, int n){ y = m; c = n;};
}node;
struct cmp
{
bool operator ()(const int &a, const int &b) const
{
if (d2[a] > d2[b]) return 1;
return 0;
};
};
int x;
char ax[dim];
int pz;
inline void cit(int &x){
x = 0;
while (ax[pz] < '0' || ax[pz] > '9')
if (++pz == dim)
fread (ax, 1, dim, stdin), pz = 0;
while (ax[pz] >= '0' && ax[pz] <= '9'){
x = x * 10 + ax[pz] - '0';
if (++pz == dim)
fread (ax, 1, dim, stdin), pz = 0;
}
}
int N, M, A, B, K, s, i;
vector <nod> v[250004];
vector <nod> :: iterator it, fin;
priority_queue < int, vector <int>, cmp > Q;
int main()
{
freopen (iname, "r", stdin);
freopen (oname, "w", stdout);
cit(N); cit(M); cit(A); cit(B);
for (i = 1; i <= N; ++i) d[i] = 1004;
while (M--){
cit(s); cit(node.y); cit(node.c);
v[s].push_back(nod(node.y, node.c));
//fprintf (stderr, "%d %d %d\n", s, node.y, node.c);
}
memset (d, 0x3f3f3f3f, sizeof(d));
memset (d2, 0,sizeof(d2));
d2[A] = 0;
d[A] = 0; K = 0;
Q.push(A);
while (!Q.empty()){
x = Q.top();
Q.pop();
if (x == B) {
printf ("%d\n", d[x]);
return 0;
}
it = v[x].begin();
fin = v[x].end();
for (; it != fin; ++it){
d2[it -> y] = max(it -> c, d2[x]);
if (d[ it->y ] > d2[ it->y ]) {
d[it->y] = d2[it->y];
Q.push(it -> y);
}
}
}
/*for (i = 1; i <= N; ++i)
printf ("%d ", d[i]);
printf ("\n");
*/printf("%d\n", d[B]);
return 0;
}