Language: C++

#include <iostream>
#include <queue>
#include <vector>

using namespace std;

template <typename T> struct Edge {
  T dst, cost;
  Edge(int dst, int cost) : dst(dst), cost(cost) {}
  bool operator>(const Edge<T> &rhs) const { return cost > rhs.cost; }
};

const int INF = 1 << 30;

template <typename T> vector<T> dijkstra(vector<vector<Edge<T>>> tree, T src) {
  size_t V = tree.size();
  vector<T> dist = vector<T>(V, INF);
  priority_queue<Edge<T>, vector<Edge<T>>, greater<Edge<T>>> queue;

  dist[src] = 0;
  queue.push(Edge<T>(src, 0));
  while (!queue.empty()) {
    Edge<T> t = queue.top();
    queue.pop();
    int v = t.dst, cost = t.cost;

    if (dist[v] < cost) {
      continue;
    }
    for (size_t i = 0; i < V; i++) {
      Edge<T> e = tree[v][i];
      if (dist[v] + e.cost < dist[e.dst]) {
        dist[e.dst] = dist[v] + e.cost;
        queue.push(Edge<T>(e.dst, dist[e.dst]));
      }
    }
  }

  return dist;
}

int main(int argc, char const *argv[]) {
  int V, E, r;
  cin >> V >> E >> r;

  vector<vector<Edge<int>>> tree =
      vector<vector<Edge<int>>>(V, vector<Edge<int>>(0));

  for (size_t i = 0; i < E; i++) {
    int s, t, d;
    cin >> s >> t >> d;
    tree[s].push_back(Edge<int>(t, d));
  }

  vector<int> ret = dijkstra(tree, r);
  for (size_t i = 0; i < V; i++) {
    int d = ret[i];
    if (d >= INF) {
      cout << "INF" << endl;
    } else {
      cout << d << endl;
    }
  }

  return 0;
}


Compiler output:
In file included from /usr/include/c++/14/bits/alloc_traits.h:33,
                 from /usr/include/c++/14/ext/alloc_traits.h:34,
                 from /usr/include/c++/14/bits/basic_string.h:39,
                 from /usr/include/c++/14/string:54,
                 from /usr/include/c++/14/bits/locale_classes.h:40,
                 from /usr/include/c++/14/bits/ios_base.h:41,
                 from /usr/include/c++/14/ios:44,
                 from /usr/include/c++/14/ostream:40,
                 from /usr/include/c++/14/iostream:41,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_construct.h: In instantiation of 'void std::_Construct(_Tp*, _Args&& ...) [with _Tp = Edge<int>; _Args = {}]':
/usr/include/c++/14/bits/stl_uninitialized.h:643:18:   required from 'static _ForwardIterator std::__uninitialized_default_n_1<_TrivialValueType>::__uninit_default_n(_ForwardIterator, _Size) [with _ForwardIterator = Edge<int>*; _Size = long unsigned int; bool _TrivialValueType = false]'
  643 |                 std::_Construct(std::__addressof(*__cur));
      |                 ~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_uninitialized.h:712:20:   required from '_ForwardIterator std::__uninitialized_default_n(_ForwardIterator, _Size) [with _ForwardIterator = Edge<int>*; _Size = long unsigned int]'
  710 |       return __uninitialized_default_n_1<__is_trivial(_ValueType)
      |              ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  711 |                                          && __can_fill>::
      |                                          ~~~~~~~~~~~~~~~~
  712 |         __uninit_default_n(__first, __n);
      |         ~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_uninitialized.h:779:44:   required from '_ForwardIterator std::__uninitialized_default_n_a(_ForwardIterator, _Size, allocator<_Tp>&) [with _ForwardIterator = Edge<int>*; _Size = long unsigned int; _Tp = Edge<int>]'
  779 |     { return std::__uninitialized_default_n(__first, __n); }
      |              ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_vector.h:1720:36:   required from 'void std::vector<_Tp, _Alloc>::_M_default_initialize(size_type) [with _Tp = Edge<int>; _Alloc = std::allocator<Edge<int> >; size_type = long unsigned int]'
 1720 |           std::__uninitialized_default_n_a(this->_M_impl._M_start, __n,
      |           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 1721 |                                            _M_get_Tp_allocator());
      |                                            ~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_vector.h:558:9:   required from 'std::vector<_Tp, _Alloc>::vector(size_type, const allocator_type&) [with _Tp = Edge<int>; _Alloc = std::allocator<Edge<int> >; size_type = long unsigned int; allocator_type = std::allocator<Edge<int> >]'
  558 |       { _M_default_initialize(__n); }
      |         ^~~~~~~~~~~~~~~~~~~~~
a.cc:47:55:   required from here
   47 |       vector<vector<Edge<int>>>(V, vector<Edge<int>>(0));
      |                                                       ^
/usr/include/c++/14/bits/stl_construct.h:119:7: error: no matching function for call to 'Edge<int>::Edge()'
  119 |       ::new((void*)__p) _Tp(std::forward<_Args>(__args)...);
      |       ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
a.cc:9:3: note: candidate: 'Edge<T>::Edge(int, int) [with T = int]'
    9 |   Edge(int dst, int cost) : dst(dst), cost(cost) {}
      |   ^~~~
a.cc:9:3: note:   candidate expects 2 arguments, 0 provided
a.cc:7:30: note: candidate: 'constexpr Edge<int>::Edge(const Edge<int>&)'
    7 | template <typename T> struct Edge {
      |                              ^~~~
a.cc:7:30: note:   candidate expects 1 argument, 0 provided
a.cc:7:30: note: candidate: 'constexpr Edge<int>::Edge(Edge<int>&&)'
a.cc:7:30: note:   candidate expects 1 argument, 0 provided