Pagini recente » Cod sursa (job #3257389) | Cod sursa (job #1065953) | Cod sursa (job #380249) | Cod sursa (job #132725) | Cod sursa (job #1906642)
#include<fstream>
#include<vector>
using namespace std;
ifstream fin("pscnv.in");
ofstream fout("pscnv.out");
string sir;
int i, n, k, j,m,a,b,c,st,dr,sol,x,y;
vector <int> lista[1005];
vector <pair<int, short int>> v[250005];
short int d[250005];
void citeste()
{
getline(fin, sir);
//fout << sir<<"\n";
int aux = 0;
int i = 0;
int n = sir.length();
vector <int> w;
while(i < n)
{
aux = 0;
while(sir[i] <= '9' && sir[i] >= '0' && i < n)
{
aux = aux * 10 + (sir[i] - '0');
i++;
}
i++;
w.push_back(aux);
//fout<<aux<<"\n";
}
a = w[0];
b = w[1];
c = w[2];
}
int main()
{
fin >> n >> m >> x >> y;
getline(fin, sir);
for(i = 1; i <= n; i++)
{
d[i] = 20000;
}
d[x] = 0;
for(i = 1; i <= m; i++)
{
citeste();
//fin >> a >> b >> c;
v[a].push_back(make_pair(b, c));
}
lista[0].push_back(x);
short int i = 0;
while(i <= 1000)
{
int nod;
int cont = lista[i].size();
for(int j = 0; j < cont; j++)
{
nod = lista[i][j];
//fout<<nod<<"\n";
if(i == d[nod])
{
//fout << nod<<"\n";
for(int p = 0; p < v[nod].size(); p++)
{
//fout<<v[nod][p].first<<" ";
short cost = max(i, v[nod][p].second);
//fout<<cost<<"\n";
d[v[nod][p].first] = min(d[v[nod][p].first], cost);
if(d[v[nod][p].first] >= cost)
{
d[v[nod][p].first] = cost;
lista[cost].push_back(v[nod][p].first);
if(cost == i) cont++;
//cont++;
}
}
//fout << nod << "\n";
}
}
i++;
}
fout << d[y] << "\n";
}