Pagini recente » Cod sursa (job #3188097) | Cod sursa (job #3186138) | Cod sursa (job #30830) | Cod sursa (job #2866124) | Cod sursa (job #3186010)
#include <fstream>
#include <queue>
#include <vector>
using namespace std;
ifstream cin("sate.in");
ofstream cout("sate.out");
int n,m,x,y,i,j,d,pi,pf,dim[30003];
vector<pair<int,int>>s[30003];
queue<int>q;
int main()
{
cin>>n>>m>>pi>>pf;
for(i=1;i<=m;i++){
cin>>x>>y>>d;
s[x].push_back({y,d});
s[y].push_back({x,-d});
}
q.push(pi);
while(!q.empty()){
int nod=q.front();
q.pop();
for(i=0;i<s[nod].size();i++){
int nod2=s[nod][i].first;
if(dim[nod2]==0){
q.push(nod2);
dim[nod2]=dim[nod]+s[nod][i].second;
}
}
}
cout<<dim[pf];
return 0;
}