Pagini recente » Cod sursa (job #1894234) | Cod sursa (job #2958060) | Cod sursa (job #1210794) | Cod sursa (job #1871894) | Cod sursa (job #3142821)
using namespace std;
#ifdef EZ
#include "./ez/ez.h"
const string FILE_NAME = "test";
#else
#include <bits/stdc++.h>
const string FILE_NAME = "sate";
#endif
#define mp make_pair
#define mt make_tuple
#define ll long long
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define cin fin
#define cout fout
ifstream fin (FILE_NAME + ".in");
ofstream fout (FILE_NAME + ".out");
const int nMAX = 30e3;
int n, m, x, y;
vector<pair<int, int>> gf[nMAX + 1];
ll d[nMAX + 1];
void shortestPath(int nod)
{
fill(d + 1, d + n+1, LLONG_MAX>>1);
queue<pair<int, ll>> q;
q.push({x, 0});
d[x] = 0;
while (!q.empty())
{
int nod = q.front().fi;
q.pop();
if (cost != d[nod])
continue;
for (auto nex : gf[nod])
if (d[nod] + nex.se < d[nex.fi])
{
d[nex.fi] = d[nod] + nex.se;
q.push({nex.fi, d[nex.fi]});
}
}
}
int main()
{
cin >> n >> m >> x >> y;
for (int i = 1; i <= m; ++i)
{
int a, b, c;
cin >> a >> b >> c;
gf[a].eb(b, c);
gf[b].eb(a, -c);
}
shortestPath(x);
cout << d[y];
}