Mai intai trebuie sa te autentifici.
Cod sursa(job #751245)
Utilizator | Data | 24 mai 2012 23:43:00 | |
---|---|---|---|
Problema | PScNv | Scor | 50 |
Compilator | cpp | Status | done |
Runda | Arhiva de probleme | Marime | 0.94 kb |
#include <fstream>
#include <vector>
#include <queue>
using namespace std;
ifstream fin("pscnv.in");
ofstream fout("pscnv.out");
queue<int> q;
vector<pair<int,int> > v[250001];
int main()
{
int n,m,x,y,a,b,k;
fin>>n>>m>>x>>y;
for(int i=1;i<=m;i++)
{
fin>>a>>b>>k;
v[a].push_back(make_pair(b,k));
}
bool gasit=false;
for(int k=0;k<=1010 && !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;
}