Pagini recente » Cod sursa (job #2876828) | Cod sursa (job #899020) | Cod sursa (job #2236501) | Cod sursa (job #3286187) | Cod sursa (job #2671702)
#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;
const int DIM = 10000;
char buff[DIM];
int poz=0;
void citeste(int &numar)
{
numar = 0;
while (buff[poz] < '0' || buff[poz] > '9')
if (++poz == DIM)
fread(buff,1,DIM,stdin),poz=0;
while ('0'<=buff[poz] && buff[poz]<='9')
{
numar = numar*10 + buff[poz] - '0';
if (++poz == DIM)
fread(buff,1,DIM,stdin),poz=0;
}
}
void citire() {
citeste(n);
citeste(m);
citeste(ss);
citeste(ff);
for(int i = 1; i <= m; i ++) {
int x, y, k;
citeste(x);
citeste(y);
citeste(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;
}