Pagini recente » Cod sursa (job #695385) | Cod sursa (job #218783) | Cod sursa (job #919825) | Cod sursa (job #1102126) | Cod sursa (job #2454281)
#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)
{
if(k == finish) {
fout << "0";
exit(0);
}
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;
if(to == finish) {
fout << d[to];
exit(0);
}
q.push(to);
}
}
}
}
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;
}