Pagini recente » Borderou de evaluare (job #1170215) | Cod sursa (job #3349522) | Monitorul de evaluare | Cod sursa (job #45576) | Cod sursa (job #3352508)
#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();
viz[dx] = true;
for (auto i : adj[dx]){
if (viz[i.first] == false){
pos[i.first] = pos[dx] + i.second;
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;
}