Pagini recente » Cod sursa (job #1017818) | Cod sursa (job #1831419) | Cod sursa (job #1393278) | Cod sursa (job #3197338) | Cod sursa (job #751250)
Cod sursa(job #751250)
#include <fstream>
#include <vector>
#include <queue>
#include <cctype>
#include <cstring>
using namespace std;
ifstream fin("pscnv.in");
ofstream fout("pscnv.out");
queue<int> q;
vector<pair<int,int> > v[250001];
int parse(int x)
{
}
int main()
{
int n,m,x,y,a,b,k,kmax=0;
fin>>n>>m>>x>>y;
for(int i=1;i<=m;i++)
{
fin>>a>>b>>k;
v[a].push_back(make_pair(b,k));
if(k>kmax)
kmax=k;
}
bool gasit=false;
for(int k=1;k<=kmax && !gasit;k++)
{
q.push(x);
while(!q.empty())
{
int F = q.front();
for(int i=0; i<v[F].size() && !gasit;i++)
if(v[F][i].second<=k)
{
if(v[F][i].first==y)
{
fout<<k<<'\n';
gasit=true;
}
else q.push(v[F][i].first);
}
q.pop();
}
}
fin.close();
fout.close();
return 0;
}