Pagini recente » Cod sursa (job #1275752) | Cod sursa (job #3204512) | Statistici sava virginiea (elevulxxx) | Cod sursa (job #2822912) | Cod sursa (job #1202376)
#include <iostream>
#include <fstream>
#include <vector>
using namespace std;
ifstream f ("sate.in");
ofstream g ("sate.out");
int n, x, y;
struct muchie {
int nod, cost;
muchie(int nod, int cost) {
// cout << nod << ' ' << cost << endl;
this->nod = nod;
this->cost = cost;
}
};
vector <muchie> v[30001];
int d[30001];
char viz[30001];
void citeste () {
int m, a, b, c;
f >> n >> m >> x >> y;
for (int i = 1; i <= m; i++) f >> a >> b >> c, v[a].push_back(muchie(b, c)), v[b].push_back(muchie(a, c));
}
void DFS (int nod) {
if (nod != y) {
viz[nod] = 1;
int l = v[nod].size();
for (int i = 0; i < l; i++)
if (viz[v[nod][i].nod] == 0) {
if (v[nod][i].nod < nod) d[v[nod][i].nod] = d[nod] - v[nod][i].cost;
else d[v[nod][i].nod] = d[nod] + v[nod][i].cost;
DFS(v[nod][i].nod);
}
}
}
int main () {
citeste ();
DFS (x);
g << d[y] << '\n';
return 0;
}