Pagini recente » Cod sursa (job #244699) | Cod sursa (job #2919040) | Cod sursa (job #1612980) | Cod sursa (job #2282205) | Cod sursa (job #593126)
Cod sursa(job #593126)
#include <cstring>
#include <fstream>
#include <algorithm>
#include <vector>
using namespace std;
typedef vector<pair<int, int> > VP;
const int INF = 0x3f3f3f3f;
//char parse[10000000], *now;
int N, M, X, Y;
vector<pair<int, int> > V[250002];
vector<int> L[1002];
int minC[250002], where[250002];
bool S[250002];
/*int get()
{
int number = 0;
while (!('0' <= *now && *now <= '9')) ++now;
while ('0' <= *now && *now <= '9')
number *= 10, number += *now - '0', ++now;
return number;
}*/
int main()
{
ifstream fin("pscnv.in");
ofstream fout("pscnv.out");
//fin.getline(parse, sizeof(parse), '\0');
//now = parse;
//N = get();
//M = get();
//X = get();
//Y = get();
fin >> N >> M >> X >> Y;
for (int i = 1, nod1, nod2, cost; i <= M; ++i)
{
//nod1 = get();
//nod2 = get();
//cost = get();
fin >> nod1 >> nod2 >> cost;
if (nod1 != nod2)
V[nod1].push_back(make_pair(nod2, cost));
}
for (int i = 1; i <= N; ++i)
minC[i] = INF;
minC[X] = 0;
S[X] = true;
for (VP::iterator it = V[X].begin(); it != V[X].end(); ++it)
{
minC[it->first] = it->second;
L[minC[it->first]].push_back(it->first);
}
int pos = 1;
for (int step = 1; step < N; ++step)
{
int now = 0;
do
{
while (pos <= 1000 && L[pos].empty()) ++pos;
if (pos > 1000) break;
now = L[pos].back();
L[pos].pop_back();
if (S[now]) now = 0;
} while (now == 0);
if (now == 0) break;
S[now] = true;
for (VP::iterator it = V[now].begin(); it != V[now].end(); ++it)
if (max(minC[now], it->second) < minC[it->first])
{
minC[it->first] = max(minC[now], it->second);
L[minC[it->first]].push_back(it->first);
}
}
fout << minC[Y];
fin.close();
fout.close();
}