Pagini recente » Cod sursa (job #570979) | Cod sursa (job #2260254) | Cod sursa (job #1873992) | Cod sursa (job #1513047) | Cod sursa (job #2398948)
#include <fstream>
#include <vector>
#include <queue>
#include <climits>
using namespace std;
#define INF INT_MAX
ifstream f("pscnv.in");
ofstream g("pscnv.out");
#define dim 8192
char ax[dim];
int pz = 0;
void readInt(int &x) {
x = 0;
while (ax[pz] < '0' || ax[pz] > '9')
if (++pz == dim)
f.read(ax, dim), pz = 0;
while (ax[pz] >= '0' && ax[pz] <= '9') {
x = x * 10 + ax[pz] - '0';
if (++pz == dim)
f.read(ax, dim), pz = 0;
}
}
int n, m, x, y, dp[250001];
struct muchie{
int nod, pond;
};
vector<muchie> a[250001];
queue<int> Q;
void parcurgere(int nod) {
Q.pop();
if (nod - y)
for (int i = 0; i < a[nod].size(); ++i) {
muchie v = a[nod][i];
if (dp[v.nod] == INF) {
dp[v.nod] = max(v.pond, dp[nod]);
Q.push(v.nod);
}
else if (dp[nod] < dp[v.nod] && v.pond < dp[v.nod]) {
dp[v.nod] = max(v.pond, dp[nod]);
Q.push(v.nod);
}
}
}
int main()
{
readInt(n); readInt(m); readInt(x); readInt(y);
int d, b, c;
for (int i = 1; i <= m; ++i) {
readInt(d); readInt(b); readInt(c);
muchie l;
l.nod = b;
l.pond = c;
a[d].push_back(l);
}
for (int i = 1; i <= n; ++i) dp[i] = INF;
dp[x] = 0;
Q.push(x);
while (!Q.empty()) parcurgere(Q.front());
g << dp[y] << '\n';
return 0;
}