Pagini recente » Cod sursa (job #2763597) | Cod sursa (job #575870) | Cod sursa (job #3183101) | Cod sursa (job #3272903) | Cod sursa (job #2825587)
#include <fstream>
#include <vector>
#include <bitset>
#include <queue>
using namespace std;
ifstream fin("sate.in");
ofstream fout("sate.out");
int n, m, x, y, s;
vector< pair<int, int> > G[30005];
bitset<30005> v;
void bfs(int nd) {
queue<int> Q;
Q.push({nd});
v[nd] = true;
while(!Q.empty()) {
int nod = Q.front();
Q.pop();
for(auto it : G[nod]) {
if(!v[it.first]) {
v[it.first] = true;
s += it.second;
if(it.first == y) {
fout << s;
exit(0);
}
Q.push(it.first);
}
}
}
}
int main() {
fin >> n >> m >> x >> y;
for(int i = 1; i <= m; i++) {
int a, b, c;
fin >> a >> b >> c;
G[a].push_back({b, c});
G[b].push_back({a, -c});
}
bfs(x);
return 0;
}