Pagini recente » Cod sursa (job #1470503) | Cod sursa (job #1179983) | Cod sursa (job #2536045) | Cod sursa (job #1625549) | Cod sursa (job #1253145)
#include <iostream>
#include <fstream>
#include <vector>
#include <queue>
#define N 30005
#define oo 200000000
using namespace std;
ifstream fin("sate.in");
ofstream fout("sate.out");
struct str
{
int nod,cost;
};
vector<str> a[N];
queue <int> q;
int d[N],v[N];
int n,m,start,stop;
void Read()
{
fin>>n>>m>>start>>stop;
int i,j,x,y,c;
str w;
for(i=1; i<=n; i++)
{
fin>>x>>y>>c;
w.nod=y;
w.cost=c;
a[x].push_back(w);
w.nod=x;
w.cost=c*-1;
a[y].push_back(w);
}
}
void Rez()
{
int i;
for(i=1; i<=n; i++)
d[i]=oo;
d[start]=0;
int w;
str x;
q.push(start);
while(!q.empty())
{
w=q.front();
q.pop();
// v[w]=0;
for(i=0; i<a[w].size(); i++)
{
x=a[w][i];
if(v[x.nod]==0)
{
d[x.nod]=d[w]+x.cost;
q.push(x.nod);
v[x.nod]=1;
if(x.nod==stop) return ;
}
}
}
}
int main()
{
Read();
Rez();
fout<<d[stop];
return 0;
}