Pagini recente » Cod sursa (job #2862203) | Cod sursa (job #1374562) | Cod sursa (job #784761) | Cod sursa (job #2181628) | Cod sursa (job #488185)
Cod sursa(job #488185)
#include <stdio.h>
#include <vector>
#include <queue>
#include <fstream>
#define NMAX 250005
#define KMAX 1005
#define LMAX 45
#define pb push_back
#define mp make_pair
#define f first
#define s second
using namespace std;
int n,m,a,b,cost[NMAX];
vector < pair<int,int> > A[NMAX];
queue <int> B[KMAX];
ifstream in("pscnv.in");
ofstream out("pscnv.out");
void read()
{
in>>n>>m>>a>>b;
int i,x,y,z,poz;
for (i=1; i<=m; i++)
{
in>>x>>y>>z;
A[x].pb(mp(y,z));
A[y].pb(mp(x,z));
}
}
inline int max(int x,int y)
{
return x>y ? x : y;
}
void init()
{
int i;
for (i=1; i<=n; i++)
cost[i]=KMAX;
}
void solve()
{
int i,j,x,x1,y1,new_list;
cost[a]=0;
B[0].push(a);
for (i=0; i<=1000; i++)
{
while (!B[i].empty())
{
x=B[i].front(); B[i].pop();
if (x==b)
return ;
if (cost[x]==i)
{
for (j=0; j<A[x].size(); j++)
{
x1=A[x][j].f; y1=A[x][j].s;
new_list=max(i,y1);
if (cost[x1]>new_list)
{
cost[x1]=new_list;
B[new_list].push(x1);
}
}
}
}
}
}
int main()
{
read();
init();
solve();
out<<cost[b]<<'\n';
return 0;
}