Pagini recente » Cod sursa (job #1911373) | Cod sursa (job #2683636) | Cod sursa (job #2610578) | Cod sursa (job #1638758) | Cod sursa (job #1911261)
#include <cstdio>
#include<vector>
#include<deque>
#include<cstring>
using namespace std;
int n,m,X,Y;
int VIZ[30001],D[30001];
struct rec{int c,d;}k;
vector<rec>graf[30001];
deque<int>ST;
void bfs(int nod)
{
int i;
VIZ[nod]=1;
ST.push_back(nod);
while(!ST.empty())
{
for(i=0;i<graf[ST.front()].size();i++)
if(!VIZ[graf[ST.front()][i].c])
{
VIZ[graf[ST.front()][i].c]=1;
if(graf[ST.front()][i].c>ST.front())
D[graf[ST.front()][i].c]=D[ST.front()]+graf[ST.front()][i].d;
else D[graf[ST.front()][i].c]=D[ST.front()]-graf[ST.front()][i].d;
ST.push_back(graf[ST.front()][i].c);
}
ST.pop_front();
}
}
int main()
{
freopen("sate.in","r",stdin);
freopen("sate.out","w",stdout);
scanf("%d%d%d%d",&n,&m,&X,&Y);
for(int i=1,x,y,d;i<=m;i++)
{
scanf("%d%d%d",&x,&y,&d);
k.c=y;
k.d=d;
graf[x].push_back(k);
k.c=x;
graf[y].push_back(k);
}
bfs(X);
printf("%d\n",D[Y]);
return 0;
}