Pagini recente » Cod sursa (job #2735689) | Cod sursa (job #80136) | Cod sursa (job #3031848) | Cod sursa (job #2540545) | Cod sursa (job #3272291)
#include <bits/stdc++.h>
using namespace std;
ifstream fin("sate.in");
ofstream fout("sate.out");
vector< pair<int, int> > G[30005];
int n,m, x, y;
int d[100025], viz[100025];
void BFS(int x)
{
int t;
queue<int> q;
q.push(x);
d[x] = 0;
viz[x] = 1;
while(!q.empty())
{
t = q.front();
q.pop();
for(auto e : G[t])
if(!viz[e.first])
{
viz[e.first] = 1;
if(e.first > t)
d[e.first] = d[t] + e.second;
else
d[e.first] = d[t] - e.second;
q.push(e.first);
}
}
}
int main()
{
int i,j,c;
fin >> n >> m >> x >> y;
while(m--)
{
fin >> i >> j >> c;
G[i].push_back({j, c});
G[j].push_back({i, c});
}
BFS(x);
fout << d[y];
return 0;
}