Pagini recente » Cod sursa (job #1077062) | Cod sursa (job #196500) | Cod sursa (job #2420323) | Cod sursa (job #269893) | Cod sursa (job #2454272)
#include <bits/stdc++.h>
using namespace std;
ifstream fin ("sate.in");
ofstream fout ("sate.out");
vector < pair < int, int > > a[30005];
void bfs(int k, int finish)
{
vector < bool > f(30005);
vector < int > d(30005);
queue < int > q;
q.push(k);
f[k] = true;
while(!q.empty()) {
int x = q.front();
q.pop();
for(auto v : a[x]) {
int to = v.first;
int w = v.second;
if(!f[to]) {
f[to] = true;
d[to] = d[x] + w;
q.push(to);
}
}
}
fout << d[finish];
}
int main()
{
ios::sync_with_stdio(false);
fin.tie(0);
int n, m, f, l;
fin >> n >> m >> f >> l;
for(int i = 1; i <= m; ++i) {
int x, y, w;
fin >> x >> y >> w;
a[x].push_back({y, w});
a[y].push_back({x, -w});
}
bfs(f, l);
return 0;
}