Pagini recente » Cod sursa (job #257073) | Cod sursa (job #2761930) | Cod sursa (job #1667376) | Cod sursa (job #435624) | Cod sursa (job #1824457)
#include <iostream>
#include <vector>
#include <queue>
#include <cstdio>
#define M 100056
using namespace std;
vector <int> A[M];
vector <long> cost[M];
queue<int> coada;
int n,m,i,j,x,y,el,G[M];
bool viz[M];
long costf[M];
inline void lee(int x)
{
coada.push(x);
viz[x]=1;
while(!coada.empty())
{
el=coada.front();
coada.pop();
for(int k=0;k<A[el].size();k++)
{
if(viz[A[el][k]]==0)
{
costf[A[el][k]]=costf[A[el][k]]+costf[el]+cost[el][k];
if(A[el][k]==y)
return;
coada.push(A[el][k]);
viz[A[el][k]]=1;
}
}
}
}
int main()
{
int x1,y1,cos;
freopen("sate.in","r",stdin);
freopen("sate.out","w",stdout);
scanf("%d%d%d%d",&n,&m,&x,&y);
while(m!=0)
{
scanf("%d%d%d",&x1,&y1,&cos);
A[x1].push_back(y1);
A[y1].push_back(x1);
cost[x1].push_back(cos);
cost[y1].push_back((-1)*cos);
m--;
}
lee(x);
printf("%d",costf[y]);
return 0;
}