Pagini recente » Cod sursa (job #704723) | Cod sursa (job #1934408) | Cod sursa (job #3211660) | Cod sursa (job #22822) | Cod sursa (job #2447123)
#include <fstream>
#include <queue>
using namespace std;
ifstream fin ("sate.in");
ofstream fout ("sate.out");
int n, m, x, y, a, b, c, marcat[30005];
queue <int> vecin[30005], cost[30005], q;
int main() {
fin >> n >> m >> x >> y;
for (int i = 1; i <= m; ++i) {
fin >> a >> b >> c;
vecin[a].push(b);
cost[a].push(c);
vecin[b].push(a);
cost[b].push(c);
}
int nod;
q.push(x);
while (!q.empty()) {
nod = q.front();
q.pop();
while (!vecin[nod].empty()) {
b = vecin[nod].front();
vecin[nod].pop();
c = cost[nod].front();
cost[nod].pop();
if (marcat[b])
continue;
if (b < nod)
marcat[b] = marcat[nod] - c;
else marcat[b] = marcat[nod] + c;
q.push(b);
if (b == y) {
fout << marcat[b];
return 0;
}
}
}
return 0;
}