Pagini recente » Cod sursa (job #952185) | Cod sursa (job #655784) | Cod sursa (job #943116) | Cod sursa (job #1081259) | Cod sursa (job #949467)
Cod sursa(job #949467)
// solutia 1 - Dijkstra modificat
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#define dim 8192
using namespace std;
const char iname[] = "pscnv.in";
const char oname[] = "pscnv.out";
int d[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 (d[a] > d[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));
d[A] = 0; K = 0;
Q.push(A);
while (!Q.empty()){
x = Q.top();
Q.pop();
it = v[x].begin();
fin = v[x].end();
for (; it != fin; ++it){
if (it -> c < d[it -> y]){
d[it -> y] = it -> c;
Q.push(it -> y);
}
}
}
/*for (i = 1; i <= N; ++i)
printf ("%d ", d[i]);
printf ("\n");
*/printf("%d\n", d[B]);
return 0;
}