Pagini recente » Cod sursa (job #1080332) | Cod sursa (job #324878) | Cod sursa (job #3123183) | Cod sursa (job #1578228) | Cod sursa (job #3298752)
#include <bits/stdc++.h>
using namespace std;
ifstream fcin("pscnv.in");
ofstream fcout("pscnv.out");
typedef long long ll;
const int N = 25e4 + 5;
const int M = 1e3 + 5;
vector<vector<int>> L(M);
vector<vector<pair<int, int>>> h(N);
int n, m, x, y, d[N], a, b, c;
bool viz[N];
int main()
{
fcin >> n >> m >> x >> y;
while (m--)
{
fcin >> a >> b >> c;
h[a].push_back({b, c});
}
for (int i = 1; i <= n; i++)
d[i] = 1e9;
d[x] = 0;
L[0].push_back(x);
for (int i = 0; i < M; i++)
for (int e : L[i])
if (!viz[e])
{
viz[e] = 1;
for (pair<int, int> p : h[e])
{
int nod, cost;
nod = p.first;
cost = p.second;
if (max(cost, d[e]) < d[nod])
{
d[nod] = max(cost, d[e]);
L[d[nod]].push_back(nod);
}
}
}
fcout << d[y];
fcin.close();
fcout.close();
return 0;
}