Pagini recente » Cod sursa (job #2929387) | Cod sursa (job #599357) | Cod sursa (job #341226) | Cod sursa (job #136062) | Cod sursa (job #3186565)
#include <bits/stdc++.h>
#define INF 100000000
using namespace std;
ifstream fin("sate.in");
ofstream fout("sate.out");
queue<int> q;
vector<pair<int, int>> l[30005];
int n, m, start, stop, cost[30005];
void bfs()
{
while (!q.empty())
{
int nod = q.front();
q.pop();
for (int i = 0; i < l[nod].size(); i++)
{
int vecin = l[nod][i].first;
int c = l[nod][i].second;
if (cost[vecin] == INF)
{ cost[vecin] = cost[nod] + c;
q.push(vecin);
}
}
}
}
int main()
{
fin >> n >> m >> start >> stop;
q.push(start);
for (int i = 1; i <= n; i++)
{
cost[i] = INF;
}
for (; m--;)
{
int x, y, c;
fin >> x >> y >> c;
l[x].push_back({y, c});
l[y].push_back({x, -c});
}
bfs();
fout << cost[stop]-INF;
}