Cod sursa(job #3142820)

Utilizator ezluciPirtac Eduard ezluci Data 24 iulie 2023 18:06:04
Problema Sate Scor 80
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.05 kb
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];
}