Pagini recente » Cod sursa (job #1590450) | Cod sursa (job #300564) | Cod sursa (job #1528869) | Statistici Minh Nguyen (shoob) | Cod sursa (job #1281876)
#include<cstdio>
#include<queue>
#include<vector>
using namespace std;
const int NMAX = 250009;
const int INF = 1 << 30;
vector< pair<int,int> > v[NMAX];
queue< int > coada;
int n,m,sol[NMAX],x,y,viz[NMAX],lungime;
void read()
{
freopen("pscnv.in","r",stdin);
scanf("%d%d%d%d",&n,&m,&x,&y);
int a ,b,c;
char sir[30],*p;
for(int i = 1 ; i <= m ; i++){
fgets(sir,30,stdin);
a = b = c = 0;
for(p = sir ; *p <= '9' && *p >= '0' ; p++) a= a*10 + (*p-48);
p++;
for(; *p <= '9' && *p >= '0' ; p++) b= b*10 + (*p-48);
p++;
for(; *p <= '9' && *p >= '0' ; p++) c= c*10 + (*p-48);
v[a].push_back(make_pair(b,c));
}
for(int i = 1 ; i <= n ; i++)
if(i != x)
sol[i] = INF;
}
int bmf(int start)
{
sol[start] = 0;
coada.push(start);
viz[start] = 1;
int i,k,vecin;
while( !coada.empty() )
{
k = coada.front();
viz[k] = 0;
for(i = 0 ; i < v[k].size() ; i++){
vecin = v[k][i].first;
if(sol[vecin] > max(v[k][i].second,sol[k])){
sol[vecin] = max(v[k][i].second,sol[k]);
if(!viz[vecin]){
coada.push(vecin);
viz[vecin] = 1;
}
}
}
coada.pop();
}
return sol[y];
}
int main()
{
freopen("pscnv.out","w",stdout);
read();
printf("%d",bmf(x));
return 0;
}