Pagini recente » Piese2 | Monitorul de evaluare | Monitorul de evaluare | Cod sursa (job #2018049) | Cod sursa (job #3146056)
#include <fstream>
#include <vector>
#include <queue>
using namespace std;
ifstream cin ("pscnv.in");
ofstream cout ("pscnv.out");
using pa = pair <int, int>;
const int INF = 1001;
const int N = 25e4;
int cost[N + 1];
vector <pa> g[N + 1];
int n, m, x, y, xi, yi, ki;
bool ok (int val)
{
for (int i = 1; i <= n; ++i)
cost[i] = INF;
cost[x] = 0;
queue <int> q;
q.push(x);
while (!q.empty())
{
int node = q.front();
q.pop();
for (auto it : g[node])
if (it.second <= val)
if (cost[it.first] > max(cost[node], it.second))
cost[it.first] = max(cost[node], it.second), q.push(it.first);
}
return (cost[y] != INF);
}
int cb (int st, int dr)
{
int med, last = 1;
while (st <= dr)
{
med = (st + dr) >> 1;
if (ok(med))
{
last = med;
dr = med - 1;
}
else
st = med + 1;
}
return last;
}
int main()
{
cin >> n >> m >> x >> y;
for (int i = 1; i <= m && cin >> xi >> yi >> ki; ++i)
if (xi != yi)
g[xi].push_back({yi, ki});
cout << cb (1, 1000) << '\n';
return 0;
}