Pagini recente » Cod sursa (job #2102663) | Cod sursa (job #2443075) | Cod sursa (job #1818185) | Cod sursa (job #1566395) | Cod sursa (job #1383052)
#include <cstdio>
#include <vector>
#include <queue>
#define DIM 100
#define INF 100000
#define NMAX 250005
#define max(a,b) a>b?a:b
using namespace std;
char buff[DIM+5];
int best[NMAX];
int n,m,x,y,z,nod1,nod2,poz=DIM-1;
queue <int>q;
vector <pair <int ,int > >v[NMAX];
vector <pair <int ,int > >::iterator it;
inline void citeste(int &numar)
{
numar=0;
while (buff[poz]<'0' || buff[poz]>'9')
if (poz++==DIM)poz=0,fread(buff,1,DIM,stdin);
while (buff[poz]>='0' && buff[poz]<='9')
{
numar=numar*10+buff[poz++]-'0';
if (poz==DIM)poz=0,fread(buff,1,DIM,stdin);
}
}
int main()
{
freopen("pscnv.in","r",stdin);
freopen("pscnv.out","w",stdout);
citeste(n);
citeste(m);
citeste(nod1);
citeste(nod2);
for (int i=1;i<=n;i++)best[i]=INF;
for (int i=1;i<=m;i++)
{
citeste(x);
citeste(y);
citeste(z);
v[x].push_back(make_pair(y,z));
}
best[nod1]=0;
q.push(nod1);
while (q.size())
{
int nod=q.front();
q.pop();
for (it=v[nod].begin();it!=v[nod].end();it++)
if (max(best[nod],(*it).second)<best[(*it).first])
{
q.push((*it).first);
best[(*it).first]=max(best[nod],(*it).second);
}
}
printf("%d",best[nod2]);
fclose(stdin);
fclose(stdout);
}