Pagini recente » Cod sursa (job #3331492) | Cod sursa (job #3314226) | Cod sursa (job #2191105) | Cod sursa (job #3331490) | Cod sursa (job #3340638)
#include <bits/stdc++.h>
using namespace std;
ifstream fin ("sate.in");
ofstream fout ("sate.out");
const int N_MAX = 30005, M_MAX = 100025;
int n, m, x, y, v[N_MAX], a, b, d;
vector<pair<int, int>> g[N_MAX];
void bfs (int nod) {
queue<int> q;
q.push(nod);
while (!q.empty()) {
int nod = q.front();
q.pop();
for (auto [fiu, d] : g[nod]) {
if (v[fiu] == 0) {
q.push(fiu);
v[fiu] = v[nod] + d;
///fout << v[fiu] << " " << fiu << "\n";
}
}
}
}
int main() {
fin >> n >> m >> x >> y;
for (int i = 1; i <= m; i++) {
fin >> a >> b >> d;
g[a].push_back({b, d});
g[b].push_back({a, -d});
}
bfs(x);
fout << v[y] << "\n";
return 0;
}