Pagini recente » Cod sursa (job #3331104) | Cod sursa (job #3355678) | Cod sursa (job #3308459) | Cod sursa (job #3314223) | Cod sursa (job #3352511)
#include <bits/stdc++.h>
using namespace std;
ifstream fin ("sate.in");
ofstream fout ("sate.out");
#define cin fin
#define cout fout
const int NMAX = 3e4 + 5;
vector<vector<pair<int, int>>> adj(NMAX);
bool viz[NMAX];
int n, m, x, y;
int pos[NMAX];
void bfs(){
queue<int> q;
q.push(x);
viz[x] = true;
while (!q.empty()){
int dx = q.front();
q.pop();
for (auto i : adj[dx]){
if (viz[i.first] == false){
pos[i.first] = pos[dx] + i.second;
viz[i.first] = true;
q.push(i.first);
}
if (i.first == y){
cout << pos[i.first];
return;
}
}
}
}
int main(){
cin >> n >> m >> x >> y;
for (int i = 1, a, b, c; i <= m; ++ i){
cin >> a >> b >> c;
adj[a].push_back({b, c});
adj[b].push_back({a, -c});
}
bfs();
return 0;
}