Pagini recente » Cod sursa (job #2092811) | Cod sursa (job #1097323) | Istoria paginii propuneri/6-arhiva-educationala | Cod sursa (job #1727689) | Cod sursa (job #1911278)
#include <cstdio>
#include<vector>
#include<deque>
#include<iostream>
#include<fstream>
#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);
ifstream f("sate.in");
freopen("sate.out","w",stdout);
//scanf("%d%d%d%d",&n,&m,&X,&Y);
f>>n>>m>>X>>Y;
for(int i=1,x,y,d;i<=m;i++)
{
// scanf("%d%d%d",&x,&y,&d);
f>>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;
}