Language: C++

#include <queue>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
// ------ Class ------ //
template <class T> class Graph2 {
public:
	// ------ Variables ------ //
	static const T INF = numeric_limits<T>::max();
	int V, E; vector<vector<pair<int, T> > > G;

	// ------ Constructors ------ //
	Graph2() : V(0), E(0), G(vector<vector<pair<int, T> > >()) {}
	Graph2(int v) : V(v), E(0), G(vector<vector<pair<int, T> > >(v)) {}
	Graph2(vector<vector<pair<int, T> > > g) : V(g.size()), G(g) { for (int i = 0; i < g.size(); i++) E += g[i].size(); }

	// ------ Basic Functions ------ //
	int size() { return V; }
	void add1(int v1, int v2, T w) { G[v1].push_back(make_pair(v2, w)); E++; }
	void add2(int v1, int v2, T w) { add1(v1, v2, w); add1(v2, v1, w); }

	// ------ Operators ------ //
	bool operator==(const Graph2& g) const { return G == g.G; }
	bool operator!=(const Graph2& g) const { return G != g.G; }
	vector<pair<int, T> > operator[](int x) { return G[x]; }

	// ------ Algorithms ------ //
	vector<T> dist(int s) {
		priority_queue<pair<T, int> > que; que.push(make_pair(0, s));
		vector<T> d(V, INF); d[s] = 0;
		while (!que.empty()) {
			pair<T, int> t = que.top(); que.pop();
			int u = t.second;
			for (int i = 0; i < G[u].size(); i++) {
				int v = G[u][i].first; T e = G[u][i].second;
				if (d[v] > d[u] + e) {
					d[v] = d[u] + e;
					que.push(make_pair(-d[v], v));
				}
			}
		}
		return d;
	}
	vector<int> disttree(int s) {
		priority_queue<pair<T, int> > que; que.push(make_pair(0, s));
		vector<T> d(V, INF); d[s] = 0;
		vector<int> p(V, -1);
		while (!que.empty()) {
			pair<T, int> t = que.top(); que.pop();
			int u = t.second;
			for (int i = 0; i < G[u].size(); i++) {
				int v = G[u][i].first; T e = G[u][i].second;
				if (d[v] > d[u] + e) {
					d[v] = d[u] + e, p[v] = u;
					que.push(make_pair(-d[v], v));
				}
			}
		}
		return p;
	}
	T minspan() {
		vector<T> d(V, INF);
		vector<bool> used(V, false);
		priority_queue<pair<T, int> > que;
		for (int i = 0; i < V; i++) d[i] = INF;
		d[0] = 0; que.push(make_pair(0, 0));
		while (!que.empty()) {
			pair<T, int> pa = que.top(); que.pop();
			int u = pa.second; used[u] = true;
			for (int i = 0; i < G[u].size(); i++) {
				int v = G[u][i].first;
				if (d[v] > G[u][i].second && !used[v]) {
					d[v] = G[u][i].second; que.push(make_pair(-d[v], v));
				}
			}
		}
		T sum = 0;
		for (int i = 0; i < V; i++) sum += d[i];
		return sum;
	}
	vector<int> spantree() {
		vector<T> d(V, INF);
		vector<bool> used(V, false);
		vector<int> p(V, -1);
		priority_queue<pair<T, int> > que;
		for (int i = 0; i < V; i++) d[i] = INF;
		d[0] = 0; que.push(make_pair(0, 0));
		while (!que.empty()) {
			pair<T, int> pa = que.top(); que.pop();
			int u = pa.second; used[u] = true;
			for (int i = 0; i < G[u].size(); i++) {
				int v = G[u][i].first;
				if (d[v] > G[u][i].second && !used[v]) {
					d[v] = G[u][i].second, p[v] = u;
					que.push(make_pair(-d[v], v));
				}
			}
		}
		return p;
	}
	long long diameter() {
		vector<int> v1 = dist(0);
		vector<int> v2 = dist(max_element(v1.begin(), v1.end()) - v1.begin());
		return *max_element(v2.begin(), v2.end())
	}
};
// ------ Main ------ //
int V, E, r, s, t, w;
int main() {
	cin >> V >> E >> r;
	Graph2<int> G(V);
	for(int i = 0; i < E; i++) {
		cin >> s >> t >> w;
		G.add1(s, t, w);
	}
	vector<int> d = G.dist(r);
	for(int i = 0; i < V; i++) cout << d[i] << endl;
}

Compiler output:
a.cc:10:30: error: 'numeric_limits' was not declared in this scope
   10 |         static const T INF = numeric_limits<T>::max();
      |                              ^~~~~~~~~~~~~~
a.cc:10:46: error: expected primary-expression before '>' token
   10 |         static const T INF = numeric_limits<T>::max();
      |                                              ^
a.cc:10:52: error: no matching function for call to 'max()'
   10 |         static const T INF = numeric_limits<T>::max();
      |                                               ~~~~~^~
In file included from /usr/include/c++/14/deque:62,
                 from /usr/include/c++/14/queue:62,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_algobase.h:257:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
  257 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:257:5: note:   candidate expects 2 arguments, 0 provided
/usr/include/c++/14/bits/stl_algobase.h:303:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
  303 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note:   candidate expects 3 arguments, 0 provided
In file included from /usr/include/c++/14/algorithm:61,
                 from a.cc:4:
/usr/include/c++/14/bits/stl_algo.h:5706:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(initializer_list<_Tp>)'
 5706 |     max(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5706:5: note:   candidate expects 1 argument, 0 provided
/usr/include/c++/14/bits/stl_algo.h:5716:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(initializer_list<_Tp>, _Compare)'
 5716 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5716:5: note:   candidate expects 2 arguments, 0 provided
a.cc: In member function 'long long int Graph2<T>::diameter()':
a.cc:106:9: error: expected ';' before '}' token
  106 |         }
      |         ^