Pagini recente » Cod sursa (job #1246491) | Cod sursa (job #2686420) | Cod sursa (job #1702687) | Cod sursa (job #2300746) | Cod sursa (job #602280)
Cod sursa(job #602280)
#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;
}
}
inline void read(int &x,int &y,int &z)
{
static char s[256],*r;
static int a[3],i;
gets(s);r=s;
for (i=0;i<3;++i)
{
a[i]=0;
while (*r && (*r<'0' || *r>'9')) ++r;
while (*r>='0' && *r<='9')
a[i]= a[i]*10+*r-'0',
++r;
}
x=a[0];y=a[1];z=a[2];
}
int main()
{
int i,x,y,c;
freopen(IN,"r",stdin);
scanf("%d%d%d%d\n",&N,&M,&X,&Y);
for (i=0;i<M;++i)
//scanf("%d%d%d",&x,&y,&c),
read(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;
}