Pagini recente » Cod sursa (job #2730641) | Cod sursa (job #3323679) | Cod sursa (job #3347115) | Cod sursa (job #3316610) | Cod sursa (job #3352499)
#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;
int loc = 0;
while (!q.empty()){
int dx = q.front();
q.pop();
viz[dx] = true;
for (auto i : adj[dx]){
if (viz[i.first] == false){
loc += i.second;
q.push(i.first);
}
if (i.first == y){
cout << loc;
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;
}