Pagini recente » Cod sursa (job #1215831) | Cod sursa (job #1185607) | Cod sursa (job #2691631) | Cod sursa (job #116217) | Cod sursa (job #602277)
Cod sursa(job #602277)
#include <stdio.h>
#include <vector>
#include <queue>
#include <algorithm>
#define NMax 250010
#define INF 0x3f3f3f3f
using namespace std;
const char IN[]="pscnv.in",OUT[]="pscnv.out";
int N,M,X,Y;
int T[NMax];
bool InQue[NMax];
vector<pair<int,int> > ad[NMax];
void BellmanFord()
{
int i,x;
queue<int> qu;
for (i=0;i<=N;++i) T[i]=INF;
T[X]=-INF;
qu.push(X);
while (!qu.empty())
{
x=qu.front();qu.pop();
for ( typeof(ad[x].begin()) it=ad[x].begin();it<ad[x].end();++it)
if ( max(T[x],it->second)<T[it->first] )
{
T[it->first]=max(T[x],it->second);
if (!InQue[it->first])
qu.push(it->first),
InQue[it->first]=true;
}
InQue[x]=false;
}
}
int main()
{
int i,x,y,c;
freopen(IN,"r",stdin);
scanf("%d%d%d%d",&N,&M,&X,&Y);
for (i=0;i<M;++i)
scanf("%d%d%d",&x,&y,&c),
ad[x].push_back(make_pair(y,c)),
ad[y].push_back(make_pair(x,c));
fclose(stdin);
BellmanFord();
freopen(OUT,"w",stdout);
printf("%d\n",T[Y]);
fclose(stdout);
return 0;
}