Pagini recente » Cod sursa (job #2789743) | Rating Alexandru Constantin (alexandru.bala) | Istoria paginii utilizator/faithlambertac | Cod sursa (job #1168832) | Cod sursa (job #2783453)
#include <fstream>
#include <set>
#include <queue>
using namespace std;
ifstream cin("sate.in");
ofstream cout("sate.out");
using pii = pair<int, int>;
set<pii> graf[30005];
int main() {
int n, m, X, Y;
cin >> n >> m >> X >> Y;
for (int i = 1; i <= m; i++) {
int x, y, d;
cin >> x >> y >> d;
graf[x].insert({ y, d });
graf[y].insert({ x, -d });
}
queue<pii> q;
q.push({ X, 0 });
while (!q.empty()) {
pii &now = q.front();
if (now.first == Y) {
cout << now.second;
return 0;
}
for (pii i : graf[now.first]) {
q.push({ i.first, now.second + i.second});
}
graf[now.first].clear();
q.pop();
}
return 0;
}