Pagini recente » Cod sursa (job #491298) | Cod sursa (job #1890840) | Cod sursa (job #1020145) | Cod sursa (job #2282044) | Cod sursa (job #2215271)
#include <vector>
#include <queue>
#include <algorithm>
#include <cstdio>
using namespace std;
const int MaxN = 250001, Inf = 0x3f3f3f3f;
using PII = pair<int, int>;
using VI = vector<int>;
using VB = vector<bool>;
using VP = vector<PII>;
using VVP = vector<VP>;
VVP G;
VI d;
int n,S,F;
void ReadGraph();
void Dijkstra(int S, VI& d);
void Get (int &x);
int main() {
freopen("pscnv.in","r",stdin);
freopen("pscnv.out","w",stdout);
ReadGraph();
Dijkstra(S, d);
printf("%d",d[F]);
return 0;
}
void Dijkstra(int x, VI& d) {
priority_queue<PII, VP, greater<PII>> Q;
d = VI(n + 1, Inf);
d[x] = 0;
Q.push({0, x});
int y, w, dx;
while (!Q.empty()) {
x = Q.top().second; dx = Q.top().first;
Q.pop();
if (d[x] < dx)
continue;
for (const PII& p : G[x]) {
y = p.first;
w = p.second;
if (d[y] > max(d[x],w) ) {
d[y] = max(d[x],w);
Q.push({d[y], y});
}
}
}
}
void ReadGraph() {
int m;
Get(n); Get(m); Get(S); Get(F);
G = VVP(n + 1);
int x, y, w;
while (m--) {
Get(x); Get(y); Get(w);
G[x].push_back({y, w});
}
}
const int Lim = 1000000;
int u = Lim - 1;
char s[Lim];
void Next () {
if (++u == Lim)
std::fread(s, 1, Lim, stdin), u = 0;
}
void Get (int &x) {
for (; s[u] < '0' || s[u] > '9'; Next());
for (x = 0; s[u] >= '0' && s[u] <= '9'; Next())
x = x * 10 + s[u] - '0';
}