Pagini recente » Cod sursa (job #123356) | Cod sursa (job #2389482) | Cod sursa (job #987489) | Cod sursa (job #2631748) | Cod sursa (job #2083886)
#include <cstdio>
#include <queue>
#include <vector>
#include <cstring>
#include <algorithm>
#define pb push_back
#define mp make_pair
using namespace std;
const int nmax=250004,DIM=50000;
int poz=DIM-1;
char buff[DIM];
void citeste(int &nr)
{
nr=0;
while(!('0'<=buff[poz]&&buff[poz]<='9'))
{
if(++poz==DIM) fread(buff,1,DIM,stdin),poz=0;
}
while('0'<=buff[poz]&&buff[poz]<='9')
{
nr=nr*10 + buff[poz]-'0';
if(++poz==DIM) fread(buff,1,DIM,stdin),poz=0;
}
}
queue< int >dj;
vector< pair<int,int> > adj[nmax];
int n,m,x,y;
int cost[nmax],vis[nmax];
void dijkstra()
{
dj.push(x);
while(!dj.empty())
{
int nod=dj.front();
vis[nod]=0;
dj.pop();
for(vector< pair<int,int> >::iterator it=adj[nod].begin();it!=adj[nod].end();++it)
{
int vc=(*it).first,edg=(*it).second;
if(cost[vc]>max(cost[nod],edg))
{
cost[vc]=max(cost[nod],edg);
if(vis[vc]==0)
{
dj.push(vc);
vis[vc]=1;
}
}
}
}
}
int main()
{
freopen ("pscnv.in","r",stdin);
freopen ("pscnv.out","w",stdout);
citeste(n),citeste(m),citeste(x),citeste(y);
for(int i=1;i<=n;i++) cost[i]=0x3f3f3f3f;
cost[x]=0;
for(int i=1;i<=m;i++)
{
int a,b,c;
citeste(a),citeste(b),citeste(c);
adj[a].pb(mp(b,c));
}
dijkstra();
printf("%d\n",cost[y]);
}