Pagini recente » Cod sursa (job #2541412) | Cod sursa (job #2292450) | Cod sursa (job #382931) | Cod sursa (job #3273590) | Cod sursa (job #2671699)
#include <cstdio>
#include <vector>
#include <cstring>
#include <stack>
#include <climits>
#include <algorithm>
using namespace std;
const int nmax = 250000;
struct Dest {
int nod, cost;
};
vector <Dest> g[1 + nmax];
vector <int> d[1005];
int dist[1 + nmax];
int n, m, ss, ff;
void citire() {
scanf("%d%d%d%d", &n, &m, &ss, &ff);
for(int i = 1; i <= m; i ++) {
int x, y, k;
scanf("%d%d%d", &x, &y, &k);
g[x].push_back({y, k});
}
}
void solve() {
for(int i = 1; i <= n; i ++)
dist[i] = INT_MAX;
dist[ss] = 0;
d[0].push_back(ss);
for(int k = 0; k <= 1000; k ++) {
for(int currentNodeIndex = 0; currentNodeIndex < d[k].size(); currentNodeIndex ++) {
int currentNode = d[k][currentNodeIndex];
if(dist[currentNode] == k) {
for(auto& to: g[currentNode]) {
if(dist[to.nod] > max(dist[currentNode], to.cost)) {
dist[to.nod] = max(dist[currentNode], to.cost);
d[dist[to.nod]].push_back(to.nod);
}
}
}
}
}
}
void afisare() {
printf("%d", dist[ff]);
}
int main() {
freopen("pscnv.in", "r", stdin);
freopen("pscnv.out", "w", stdout);
citire();
solve();
afisare();
return 0;
}