Pagini recente » Cod sursa (job #3206930) | Cod sursa (job #824311) | Cod sursa (job #308985) | Cod sursa (job #2083728) | Cod sursa (job #3225072)
#include <bits/stdc++.h>
using namespace std;
ifstream fin("sate.in");
ofstream fout("sate.out");
const int inf = 1e7 + 2;
struct Muchie {
int x, y, c;
};
vector<Muchie> a[30002];
int n, m, p, q, i, x, y, c;
bool fr[30002];
static inline int Bfs(int nod) {
queue<pair<int, int>> coada;
coada.push({nod, 0});
while(!coada.empty()) {
auto nod = coada.front();
coada.pop();
fr[nod.first] = true;
if(nod.first == q) return nod.second;
for(auto vec : a[nod.first]) {
if(!fr[vec.y]) {
fr[vec.y] = true;
coada.push({vec.y, nod.second + vec.c});
}
}
}
}
int main() {
fin >> n >> m >> p >> q;
for(i = 1; i <= m; i++) {
fin >> x >> y >> c;
a[x].push_back({x, y, c});
a[y].push_back({y, x, -c});
}
fout << Bfs(p);
return 0;
}