Pagini recente » Cod sursa (job #738207) | Cod sursa (job #405771) | Cod sursa (job #3142509) | Cod sursa (job #1111628) | Cod sursa (job #1401419)
#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;
int N, M, x, y;
int D[250005];
vector<pair<int, int> > V[250005];
queue<pair<int, int> > Q;
void bellman(int nod)
{
memset(D, INF, sizeof(D));
D[nod] = 0;
Q.push(make_pair(nod, 0));
while (!Q.empty())
{
int now = Q.front().first;
int nowk = Q.front().second;
Q.pop();
for (vector<pair<int, int> >::iterator it = V[now].begin(); it != V[now].end(); ++it)
{
int k = max(nowk, it->second);
if (k < D[it->first])
{
D[it->first] = k;
Q.push(make_pair(it->first, k));
}
}
}
}
int main()
{
fin >> N >> M >> x >> y;
for (int i = 1, nod1, nod2, k; i <= M; ++i)
{
fin >> nod1 >> nod2 >> k;
if (nod1 == nod2)
continue;
V[nod1].push_back(make_pair(nod2, k));
}
bellman(x);
fout << D[y] << '\n';
fin.close();
fout.close();
return 0;
}