Pagini recente » Cod sursa (job #2736886) | Cod sursa (job #2127373) | Cod sursa (job #829236) | Cod sursa (job #1852126) | Cod sursa (job #2027644)
#include <fstream>
#include <vector>
#include <queue>
using namespace std;
const int NMAX = 30000;
int n, m, x, y, a, b, c, ans;
vector<pair<int, int>> g[NMAX + 1];
queue<pair<int, int>> q;
int Solve() {
q.push(make_pair(x, 0));
while (!q.empty()) {
int node = q.front().first;
int cost = q.front().second;
q.pop();
vector<pair<int, int>>::iterator it;
for(it = g[node].begin(); it != g[node].end(); ++it) {
pair<int, int> sat = *it;
sat.second += cost;
if(sat.first == y) {
return sat.second;
} else {
q.push(sat);
}
}
}
return 0;
}
int main() {
ifstream cin("sate.in");
ofstream cout("sate.out");
cin >> n >> m >> x >> y;
for(int i = 1; i <= m; ++i) {
cin >> a >> b >> c;
g[a].push_back(make_pair(b, c));
g[b].push_back(make_pair(a, -c));
}
cout << Solve() << "\n";
return 0;
}