Pagini recente » Cod sursa (job #1962557) | Cod sursa (job #2670708) | Cod sursa (job #1489728) | Cod sursa (job #2184828) | Cod sursa (job #1382816)
#include <fstream>
#include <vector>
#include <queue>
#include <cstring>
using namespace std;
const int kMaxN = 250005;
ifstream fin("pscnv.in");
ofstream fout("pscnv.out");
int N, M, x, y;
int mx[kMaxN];
vector<pair<int, int>> G[kMaxN];
struct HeapNode {
int node, cost;
HeapNode(int node, int cost) : node(node), cost(cost) {}
bool operator<(const HeapNode &other) const {
return cost > other.cost;
}
};
priority_queue<HeapNode> q;
char buffer[35], *p;
void Parse(int &x) {
x = 0;
while (!isdigit(*p))
++p;
while (isdigit(*p))
x = x * 10 + *(p++) - '0';
}
int main() {
fin.getline(buffer, 35);
p = buffer;
Parse(N);
Parse(M);
Parse(x);
Parse(y);
while (M--) {
int x, y, k;
fin.getline(buffer, 35);
p = buffer;
Parse(x);
Parse(y);
Parse(k);
G[x].emplace_back(y, k);
}
memset(mx, 0x3f, sizeof mx);
mx[x] = 0;
q.emplace(x, 0);
while (!q.empty()) {
int node = q.top().node;
int cost = q.top().cost;
q.pop();
if (cost != mx[node])
continue;
for (const auto &it : G[node]) {
int new_cost = max(cost, it.second);
if (new_cost < mx[it.first]) {
mx[it.first] = new_cost;
q.emplace(it.first, new_cost);
}
}
}
fout << mx[y] << "\n";
return 0;
}