Pagini recente » Cod sursa (job #1087456) | Cod sursa (job #1454154) | Cod sursa (job #2752597) | Cod sursa (job #1636770) | Cod sursa (job #2966463)
#include <bits/stdc++.h>
using namespace std;
ifstream fin("sate.in");
ofstream fout("sate.out");
#define ll long long
#define pb push_back
#define fast_read ios :: sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr)
const int maxn = 3e4;
const int maxm = 1e4;
#define INF 0x3f3f3f3f
int n, m, l, r;
vector<pair<int, int>> a[maxn + 2];
int d[maxn + 2];
void read(){
fin >> n >> m >> l >> r;
for(int i = 1; i <= m; ++i){
int x, y, cost; fin >> x >> y >> cost;
a[x].push_back({y, cost});
a[y].push_back({x, cost});
}
}
void bfs(){
queue<int> q;
q.push(l);
while(!q.empty()){
int i = q.front();
q.pop();
for(auto x : a[i]){
if(!d[x.first]){
if(i < x.first)
d[x.first] = d[i] + x.second;
else d[x.first] = d[i] - x.second;
q.push(x.first);
}
}
}
fout << d[r];
}
int main(){
read();
bfs();
return 0;
}
/*
*/