Language: C++

#include <bits/stdc++.h>
#define REP(i,n) for (long long i=0;i<(n);i++)
using namespace std;
template<typename V,typename Weight>
class Dijekstra {
private:
	struct edge {
		Weight dist;V node;V prev;
		bool operator<(edge const& a) const {
			return dist < a.dist;
		}
	};
	vector<V> trace;
	vector<vector<pair<V,Weight>>> E;
	V sz;
public:
	Weight inf = numeric_limits<Weight>::max();
	vector<Weight> D;
	Dijekstra(V v) :
		E(v),sz(v),D(v,inf),trace(v,numeric_limits<V>::max()) {}

	void addEdgeDirected(V from,V to,Weight dis){
		E[from].push_back(make_pair(to,dis));
	}
	void addEdgeUndirected(V from,V to,Weight dis){
		E[from].push_back(make_pair(to,dis));
		E[to].push_back(make_pair(from,dis));
	}

	V size() {return sz;}
	Weight & operator[] (V n) { if (0 <= n && n < sz) return D[n];} 

	void dijekstra(V start){
		priority_queue<edge,vector<edge>,greater<edge>> que;
		D[start] = 0;
		//trace[start] = start;
		que.push(edge{0,start,start});
		Weight d;V v,prev;
		while(!que.empty()){
			tie (d,v,prev) = que.top();que.pop();
			if (D[v] < d) continue; //既により最適が見つかっている
			D[v] = d;trace[v] = prev;
			for(pair<V,Weight> e : E[v]){
				if (D[e.first] <= d + e.second) continue;
				que.push(edge{d+e.second,e.first,v});
			}
		}
	}

	vector<V> show_trace(V start,V goal){ // startからgoalの最短距離上のノード
		vector<V> ret;
		for (V node = goal;node != start;node = trace[node]) ret.push_back(node);
		ret.push_back(start);
		return ret; // 配列の先頭がgoal,末尾がstart
	}
};


int main(void){
	long V,E,R;
	long s,t,d;
	cin >> V >> E >> R;
	Dijekstra<long,long> dij(V);

	REP(i,E){
		cin >> s >> t >> d;
		dij.addEdgeUndirected(s,t,d);
	}

	dij.dijekstra(R);
	REP(i,V) {
		if (dij[i] == dij.inf) cout << "INF" << endl;
		else cout << dij[i] << endl;
	}
		
	return 0;
}





Compiler output:
a.cc: In instantiation of 'void Dijekstra<V, Weight>::dijekstra(V) [with V = long int; Weight = long int]':
a.cc:70:15:   required from here
   70 |         dij.dijekstra(R);
      |         ~~~~~~~~~~~~~^~~
a.cc:40:40: error: no match for 'operator=' (operand types are 'std::tuple<long int&, long int&, long int&>' and 'const __gnu_cxx::__alloc_traits<std::allocator<Dijekstra<long int, long int>::edge>, Dijekstra<long int, long int>::edge>::value_type' {aka 'const Dijekstra<long int, long int>::edge'})
   40 |                         tie (d,v,prev) = que.top();que.pop();
      |                         ~~~~~~~~~~~~~~~^~~~~~~~~~~
In file included from /usr/include/c++/14/bits/memory_resource.h:47,
                 from /usr/include/c++/14/string:68,
                 from /usr/include/c++/14/bitset:52,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:52,
                 from a.cc:1:
/usr/include/c++/14/tuple:1930:9: note: candidate: 'template<class ... _UElements> std::__enable_if_t<((bool)__assignable<const _UElements& ...>()), std::tuple< <template-parameter-1-1> >&> std::tuple< <template-parameter-1-1> >::operator=(const std::tuple<_Args1 ...>&) [with _UElements = {_UElements ...}; _Elements = {long int&, long int&, long int&}]'
 1930 |         operator=(const tuple<_UElements...>& __in)
      |         ^~~~~~~~
/usr/include/c++/14/tuple:1930:9: note:   template argument deduction/substitution failed:
a.cc:40:40: note:   'const __gnu_cxx::__alloc_traits<std::allocator<Dijekstra<long int, long int>::edge>, Dijekstra<long int, long int>::edge>::value_type' {aka 'const Dijekstra<long int, long int>::edge'} is not derived from 'const std::tuple<_UTypes ...>'
   40 |                         tie (d,v,prev) = que.top();que.pop();
      |                         ~~~~~~~~~~~~~~~^~~~~~~~~~~
/usr/include/c++/14/tuple:1940:9: note: candidate: 'template<class ... _UElements> std::__enable_if_t<((bool)__assignable<_UElements ...>()), std::tuple< <template-parameter-1-1> >&> std::tuple< <template-parameter-1-1> >::operator=(std::tuple<_Args1 ...>&&) [with _UElements = {_UElements ...}; _Elements = {long int&, long int&, long int&}]'
 1940 |         operator=(tuple<_UElements...>&& __in)
      |         ^~~~~~~~
/usr/include/c++/14/tuple:1940:9: note:   template argument deduction/substitution failed:
a.cc:40:40: note:   types 'std::tuple<_UTypes ...>' and 'const __gnu_cxx::__alloc_traits<std::allocator<Dijekstra<long int, long int>::edge>, Dijekstra<long int, long int>::edge>::value_type' {aka 'const Dijekstra<long int, long int>::edge'} have incompatible cv-qualifiers
   40 |                         tie (d,v,prev) = que.top();que.pop();
      |                         ~~~~~~~~~~~~~~~^~~~~~~~~~~
/usr/include/c++/14/tuple:1907:7: note: candidate: 'std::tuple< <template-parameter-1-1> >& std::tuple< <template-parameter-1-1> >::operator=(std::__conditional_t<((bool)__assignable<const _Elements& ...>()), const std::tuple< <template-parameter-1-1> >&, const std::__nonesuch&>) [with _Elements = {long int&, long int&, long int&}; std::__conditional_t<((bool)__assignable<const _Elements& ...>()), const std::tuple< <template-parameter-1-1> >&, const std::__nonesuch&> = const std::tuple<long int&, long int&, long int&>&]'
 1907 |       operator=(__conditional_t<__assignable<const _Elements&...>(),
      |       ^~~~~~~~
/usr/include/c++/14/tuple:1909:52: note:   no known conversion for argument 1 from 'const __gnu_cxx::__alloc_traits<std::allocator<Dijekstra<long int, long int>::edge>, Dijekstra<long int, long int>::edge>::value_type' {aka 'const Dijekstra<long int, long int>::edge'} to 'std::__conditional_t<true, const std::tuple<long int&, long int&, long int&>&, const std::__nonesuch&>' {aka 'const std::tuple<long int&, long int&, long int&>&'}
 1907 |       operator=(__conditional_t<__assignable<const _Elements&...>(),
      |                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 1908 |                                 const tuple&,
      |                                 ~~~~~~~~~~~~~       
 1909 |                                 const __nonesuch&> __in)
      |                                 ~~~~~~~~~~~~~~~~~~~^~~~
/usr/include/c++/14/tuple:1918:7: note: candidate: 'std::tuple< <template-parameter-1-1> >& std::tuple< <template-parameter-1-1> >::operator=(std::__conditional_t<((bool)__assignable<_Elements ...>()), std::tuple< <template-parameter-1-1> >&&, std::__nonesuch&&>) [with _Elements = {long int&, long int&, long int&}; std::__conditional_t<((bool)__assignable<_Elements ...>()), std::tuple< <template-parameter-1-1> >&&, std::__nonesuch&&> = std::tuple<long int&, long int&, long int&>&&]'
 1918 |       operator=(__conditional_t<__assignable<_Elements...>(),
      |       ^~~~~~~~
/usr/include/c++/14/tuple:1920:47: note:   no known conversion for argument 1 from 'const __gnu_cxx::__alloc_traits<std::allocator<Dijekstra<long int, long int>::edge>, Dijekstra<long int, long int>::edge>::value_type' {aka 'const Dijekstra<long int, long int>::edge'} to 'std::__conditional_t<true, std::tuple<long int&, long int&, long int&>&&, std::__nonesuch&&>' {aka 'std::tuple<long int&, long int&, long int&>&&'}
 1918 |       operator=(__conditional_t<__assignable<_Elements...>(),
      |                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 1919 |                                 tuple&&,
      |                                 ~~~~~~~~       
 1920 |                                 __nonesuch&&> __in)
      |                                 ~~~~~~~~~~~~~~^~~~
In file included from /usr/include/c++/14/string:49:
/usr/include/c++/14/bits/stl_function.h: In instantiation of 'constexpr bool std::greater<_Tp>::operator()(const _Tp&, const _Tp&) const [with _Tp = Dijekstra<long int, long int>::edge]':
/usr/include/c++/14/bits/predefined_ops.h:196:23:   required from 'bool __gnu_cxx::__ops::_Iter_comp_val<_Compare>::operator()(_Iterator, _Value&) [with _Iterator = __gnu_cxx::__normal_iterator<Dijekstra<long int, long int>::edge*, std::vector<Dijekstra<long int, long int>::edge, std::allocator<Dijekstra<long int, long int>::edge> > >; _Value = Dijekstra<long int, long int>::edge; _Compare = std::greater<Dijekstra<long int, long int>::edge>]'
  196 |         { return bool(_M_comp(*__it, __val)); }
      |                       ~~~~~~~^~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_heap.h:140:48:   required from 'void std::__push_heap(_RandomAccessIterator, _Distance, _Distance, _Tp, _Compare&) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator<Dijekstra<long int, long int>::edge*, vector<Dijekstra<long int, long int>::edge, allocator<Dijekstra<long int, long int>::edge> > >; _Distance = long int; _Tp = Dijekstra<long int, long int>::edge; _Compare = __gnu_cxx::__ops::_Iter_comp_val<greater<Dijekstra<long int, long int>::edge> >]'
  140 |       while (__holeIndex > __topIndex && __comp(__first + __parent, __value))
      |                                          ~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_heap.h:216:23:   required from 'void std::push_heap(_RAIter, _RAIter, _Compare) [with _RAIter = __gnu_cxx::__normal_iterator<Dijekstra<long int, long int>::edge*, vector<Dijekstra<long int, long int>::edge, allocator<Dijekstra<long int, long int>::edge> > >; _Compare = greater<Dijekstra<long int, long int>::edge>]'
  216 |       std::__push_heap(__first, _DistanceType((__last - __first) - 1),
      |       ~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  217 |                        _DistanceType(0), _GLIBCXX_MOVE(__value), __cmp);
      |                        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_queue.h:747:16:   required from 'void std::priority_queue<_Tp, _Sequence, _Compare>::push(value_type&&) [with _Tp = Dijekstra<long int, long int>::edge; _Sequence = std::vector<Dijekstra<long int, long int>::edge, std::allocator<Dijekstra<long int, long int>::edge> >; _Compare = std::greater<Dijekstra<long int, long int>::edge>; value_type = Dijekstra<long int, long int>::edge]'
  747 |         std::push_heap(c.begin(), c.end(), comp);
      |         ~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
a.cc:37:11:   required from 'void Dijekstra<V, Weight>::dijekstra(V) [with V = long int; Weight = long int]'
   37 |                 que.push(edge{0,start,start});
      |                 ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~
a.cc:70:15:   required from here
   70 |         dij.dijekstra(R);
      |         ~~~~~~~~~~~~~^~~
/usr/include/c++/14/bits/stl_function.h:395:20: error: no match for 'operator>' (operand types are 'const Dijekstra<long int, long int>::edge' and 'const Dijekstra<long int, long int>::edge')
  395 |       { return __x > __y; }
      |                ~~~~^~~~~
In file included from /usr/include/c++/14/bits/stl_algobase.h:64,
                 from /usr/include/c++/14/algorithm:60,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51:
/usr/include/c++/14/bits/stl_pair.h:1058:5: note: candidate: 'template<class _T1, class _T2> constexpr bool std::operator>(const pair<_T1, _T2>&, const pair<_T1, _T2>&)'
 1058 |     operator>(const pair<_T1, _T2>& __x, const pair<_T1, _T2>& __y)
      |     ^~~~~~~~
/usr/include/c++/14/bits/stl_pair.h:1058:5: note:   template argument deduction/substitution failed:
/usr/include/c++/14/bits/stl_function.h:395:20: note:   'const Dijekstra<long int, long int>::edge' is not derived from 'const std::pair<_T1, _T2>'
  395 |       { return __x > __y; }
      |                ~~~~^~~~~
In file included from /usr/include/c++/14/bits/stl_algobase.h:67:
/usr/include/c++/14/bits/stl_iterator.h:462:5: note: candidate: 'template<class _Iterator> constexpr bool std::operator>(const reverse_iterator<_Iterator>&, const reverse_iterator<_Iterator>&)'
  462 |     operator>(const reverse_iterator<_Iterator>& __x,
      |     ^~~~~~~~
/usr/include/c++/14/bits/stl_iterator.h:462:5: note:   template argument deduction/substitution failed:
/usr/include/c++/14/bits/stl_function.h:395:20: note:   'const Dijekstra<long int, long int>::edge' is not derived from 'const std::reverse_iterator<_Iterator>'
  395 |       { return __x > __y;