Pagini recente » Borderou de evaluare (job #2190410) | Borderou de evaluare (job #1360981) | Cod sursa (job #1407194) | Cod sursa (job #1442705) | Cod sursa (job #1394134)
#include <fstream>
#include<queue>
#include<algorithm>
#define valoare 99999
using namespace std;
int main()
{
long *dist,k,i,x,y,n,m,b,c,d;
vector< pair <long,long> > *v;
queue<long> q;
ifstream f("sate.in");
ofstream g("sate.out");
f >> n >> m >> b >>c;
v = new vector< pair< long,long > >[n+1];
dist = new long [n+1];
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=1;i<=n;i++)
{
dist[i]=valoare;
}
dist[b]=0;
q.push(b);
while(!q.empty())
{
k=q.front();
q.pop();
for(vector< pair<long,long > >::iterator i=v[k].begin();i!=v[k].end();i++)
{
if(dist[i->first]==valoare)
{
dist[i->first]=dist[k]+i->second;
if(i->first==c)
{
g<<dist[i->first];
return 0;
}
q.push(i->first);
}
}
}
f.close();
g.close();
return 0;
}