Pagini recente » Cod sursa (job #1156133) | Cod sursa (job #2547928) | Cod sursa (job #225474) | Cod sursa (job #2318699) | Cod sursa (job #2405368)
#include <fstream>
#include <vector>
#include <climits>
using namespace std;
ifstream f("pscnv.in");
ofstream g("pscnv.out");
#define dim 8192
#define nmax 250001
int pz, n, m, x, y, a, b, c, poz[nmax], pond[nmax], mini;
struct muchie{
int nod, cost;
};
char ax[dim];
vector<muchie> v[nmax];
vector<int> d[1002];
void cit(int &x) {
x = 0;
while (ax[pz] < '0' || ax[pz] > '9') {
if (++pz == dim) f.read(ax, dim), pz = 0;
}
while (ax[pz] >= '0' && ax[pz] <= '9') {
x = x * 10 + ax[pz] - '0';
if (++pz == dim) f.read(ax, dim), pz = 0;
}
}
void adaug(int nod) {
swap(d[mini][0],d[mini][d[mini].size() - 1]);
poz[d[mini][0]] = 0;
d[mini].pop_back();
for (int i = 0; i < v[nod].size(); ++i) {
x = v[nod][i].nod;
if (max(v[nod][i].cost,pond[nod]) < pond[x]) {
if (pond[x] < INT_MAX) {
swap(d[pond[x]][poz[x]],d[pond[x]][d[pond[x]].size() - 1]);
poz[d[pond[x]][poz[x]]] = poz[x];
d[pond[x]].pop_back();
}
pond[x] = max(v[nod][i].cost,pond[nod]);
d[pond[x]].push_back(x);
poz[x] = d[pond[x]].size() - 1;
}
mini = min(mini,pond[x]);
}
while (d[mini].empty() && mini < 1000) ++mini;
}
int main()
{
cit(n), cit(m), cit(x), cit(y);
for (int i = 1; i <= m; ++i) {
cit(a), cit(b), cit(c);
if (a != y && b != x) {
muchie l;
l.nod = b, l.cost = c;
v[a].push_back(l);
}
}
for (int i = 1; i <= n; ++i) pond[i] = INT_MAX;
pond[x] = 0, mini = 1;
d[mini].push_back(x);
while (!d[mini].empty()) adaug(d[mini][0]);
g << pond[y] << '\n';
return 0;
}