Pagini recente » Cod sursa (job #2177654) | Cod sursa (job #1948458) | Cod sursa (job #221819) | Cod sursa (job #2665596) | Cod sursa (job #1990416)
/**
O(m log Val)
**/
#include<bits/stdc++.h>
#define maxN 250005
#define INF 1005
using namespace std;
int n,m,x,y,c,st,dr,mid,sol;
bool seen[maxN];
deque<int> q;
vector<pair<int,int> > v[maxN];
inline void RunBfs(int val)
{
q.push_back(x);
seen[x]=1;
while(!q.empty())
{
int nod=q.front();
q.pop_front();
for(vector<pair<int,int> >::iterator it=v[nod].begin();it!=v[nod].end();it++)
{
if(seen[it->first] || it->second>val) continue;
seen[it->first]=1;
q.push_back(it->first);
}
}
}
int main()
{
freopen("pscnv.in","r",stdin);
freopen("pscnv.out","w",stdout);
scanf("%d%d%d%d",&n,&m,&x,&y);
for(int i=1;i<=m;i++)
{
scanf("%d%d%d",&x,&y,&c);
v[x].push_back({y,c});
v[y].push_back({x,c});
}
st=0;
dr=INF;
while(st<=dr)
{
int mid=st+((dr-st)>>1);
memset(seen,0,sizeof(seen));
RunBfs(mid);
if(seen[y])
{
sol=mid;
dr=mid-1;
}
else st=mid+1;
}
printf("%d\n",sol);
return 0;
}