Pagini recente » Istoria paginii utilizator/ana_papara | Diferente pentru winter-challenge-2008/runda-2/solutii intre reviziile 11 si 10 | Istoria paginii runda/euclid | Diferente pentru utilizator/tudorbuhnia intre reviziile 43 si 42 | Cod sursa (job #2783447)
#include <fstream>
#include <set>
#include <queue>
using namespace std;
ifstream cin("sate.in");
ofstream cout("sate.out");
set<pair<int, int>> 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<pair<int, int>> q;
q.push({ X, 0 });
while (!q.empty()) {
auto now = q.front();
q.pop();
if (now.first == Y) {
cout << now.second;
return 0;
}
for (auto i : graf[now.first]) {
q.push({ i.first, now.second + (i.first > now.first ? i.second : -i.second)});
}
}
return 0;
}