Pagini recente » Cod sursa (job #3121824) | Cod sursa (job #1212528) | Cod sursa (job #2493245) | Cod sursa (job #1180215) | Cod sursa (job #1401485)
#include <fstream>
#include <vector>
#include <algorithm>
#include <queue>
#include <cstring>
using namespace std;
ifstream fin("pscnv.in");
ofstream fout("pscnv.out");
const int INF = 0x3f3f3f3f;
char sir[50];
int N, M, x, y;
int nod1, nod2, cost;
int D[250005];
vector<pair<int, int> > V[250005];
struct muchie
{
int nod, d;
bool operator < (const muchie& m) const
{
if (m.d < d) return true;
return false;
}
};
priority_queue<muchie> Q;
char parse[100], *now;
inline void verify()
{
if (*now == 0)
{
fin.get(parse, sizeof(parse), '\0');
now = parse;
}
}
int get()
{
while (*now != '-' && (*now < '0' || *now > '9'))
{
++now;
verify();
}
bool neg = false;
if (*now == '-')
{
neg = true;
++now;
verify();
}
int num = 0;
while (*now >= '0' && *now <= '9')
{
num = num * 10 + (*now - '0');
++now;
verify();
}
if (neg) num *= -1;
return num;
}
void add(int nod)
{
muchie m;
for (vector<pair<int, int> >::iterator it = V[nod].begin(); it != V[nod].end(); ++it)
{
if (!D[it->first])
{
m.nod = it->first;
m.d = max(D[nod], it->second);
Q.push(m);
}
}
}
void djk(int nod)
{
D[nod] = 0;
add(nod);
muchie m;
while (!Q.empty())
{
m = Q.top();
Q.pop();
if (D[m.nod])
continue;
D[m.nod] = m.d;
if (m.nod == y)
break;
add(m.nod);
}
}
int main()
{
now = parse;
verify();
N = get();
M = get();
x = get();
y = get();
for (int i = 1, nod1, nod2, cost; i <= M; ++i)
{
nod1 = get();
nod2 = get();
cost = get();
V[nod1].push_back(make_pair(nod2, cost));
}
djk(x);
fout << D[y] << '\n';
fin.close();
fout.close();
return 0;
}