Pagini recente » Cod sursa (job #1192674) | Cod sursa (job #2111196) | Cod sursa (job #1018944) | Cod sursa (job #319851) | Cod sursa (job #1952770)
#include <cstdio>
#include <vector>
#include <queue>
using namespace std;
int n,m,in,sf,x,y,k,i,v[250005],pr[250005];
vector <int> w[250005];
vector <int> l[250005];
queue <int> q;
int main()
{
FILE *f=fopen("pscnv.in","r");
FILE *g=fopen("pscnv.out","w");
fscanf(f,"%d%d%d%d",&n,&m,&in,&sf);
for(i=1; i<=n; i++)
{
v[i]=1005;
w[i].push_back(0);
l[i].push_back(0);
}
for(i=1; i<=m; i++)
{
fscanf(f,"%d%d%d",&x,&y,&k);
w[x].push_back(y);
w[x][0]++;
l[x].push_back(k);
w[y].push_back(x);
w[y][0]++;
l[y].push_back(k);
}
v[in]=0;
pr[in]=1;
q.push(in);
while(!q.empty())
{
x=q.front();
q.pop();
pr[x]=0;
for(i=1; i<=w[x][0]; i++)
{
y=w[x][i];
if(v[y]>max(v[x],l[x][i]))
{
v[y]=max(v[x],l[x][i]);
if(pr[y]==0)
{
q.push(y);
pr[y]=1;
}
}
}
}
fprintf(g,"%d\n",v[sf]);
fclose(f); fclose(g);
return 0;
}