Pagini recente » Cod sursa (job #2251190) | Cod sursa (job #2650588) | Cod sursa (job #2146026) | Cod sursa (job #2293813) | Cod sursa (job #1394113)
#include <iostream>
#include <fstream>
#include <vector>
#include<queue>
using namespace std;
int main()
{
int dist[30001],k, j, i, n, m, b, c, x, y, d, vizitat[30001],parinte[30001];
pair<int,int> pereche;
vector< pair <int,int> > v[30001];
queue<int> q;
bool gasit=0;
ifstream f("sate.in");
ofstream g("sate.out");
f >> n >> m >> b >>c;
for(i=0;i<n;i++)
{
parinte[i]=vizitat[i]=0;
}
for(i=0;i<m;i++)
{
f >> x >> y >> d;
v[x].push_back(make_pair(y,d));
v[y].push_back(make_pair(x,-d));
}
for(i=0;i<n;i++)
{
dist[i]=-9999;
}
dist[b]=0;
q.push(b);
while(!q.empty())
{
k=q.front();
q.pop();
for(i=0;i<v[k].size();i++)
{
if(dist[v[k][i].first]==-9999)
{
dist[v[k][i].first]=dist[k]+v[k][i].second;
}
if(v[k][i].first==c)
{
g<<dist[v[k][i].first];
return 0;
}
q.push(v[k][i].first);
}
}
f.close();
g.close();
return 0;
}