Pagini recente » Cod sursa (job #2712220) | Cod sursa (job #2097865) | Cod sursa (job #2131963) | Cod sursa (job #1331734) | Cod sursa (job #3142820)
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);
d[x] = 0;
bool okbro = true;
while (okbro)
{
okbro = false;
for (int a = 1; a <= n; ++a)
for (auto b : gf[a])
if (d[a] + b.se < d[b.fi])
{
d[b.fi] = d[a] + b.se;
okbro = true;
}
}
}
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];
}