Pagini recente » Cod sursa (job #399404) | Cod sursa (job #2718762) | Cod sursa (job #2599459) | Cod sursa (job #2923061) | Cod sursa (job #2975485)
#include <bits/stdc++.h>
#define N 250007
using namespace std;
ifstream fin("pscnv.in");ofstream fout("pscnv.out");
int st,dr,n,m;
vector<int> muchie_minima(N,-1);
vector<pair<int,int>>g[N];
bitset<N>viz;
void Citire()
{
fin >> n >> m >> st >> dr;
for(int i=1;i<=n;i++)
{
int x,y,c;
fin >> x >> y >> c;
g[x].push_back({c,y});
}
fin.close();
}
void Rezolvare()
{
Citire();
priority_queue<pair<int,int>> pq;
pq.push({0,st});
muchie_minima[st]=0;
while( !pq.empty() )
{
int cur=pq.top().second;
int v=-pq.top().first;
pq.pop();
if( !viz[cur] )
{
for(auto w:g[cur])
{
int nod=w.second;
int cost=w.first;
if( muchie_minima[nod]==-1 or muchie_minima[nod]>max(v,cost) )
{
muchie_minima[nod]=max(v,cost);
pq.push( {-muchie_minima[nod],nod} );
}
}
}
viz[cur]=1;
}
fout << muchie_minima[dr] << "\n";
fout.close();
}
int main()
{
Rezolvare();
return 0;
}