Language: C++

# include <iostream>
# include <queue>
# include <vector>
# include <algorithm>
# include <functional>

const int MAX_N = 100;
const int INF = 100000000;

typedef std::pair<int, int> P;

struct edge {
	int to, cost;
	edge(int _t, int _c) : to(_t), cost(_c) {}
};

int n, k;
std::vector<edge> G[MAX_N];
int d[MAX_N];

int dijkstra(int s, int g) {
	std::priority_queue<P, std::vector<P>, std::greater<P>()> que;
	std::fill(d, d + n, INF);
	d[s] = 0;
	que.push(P(0, s));
	while (!que.empty()) {
		P p = que.top(); que.pop();
		int v = p.second;
		if (v == g)
			break;
		if (d[v] < p.first)
			continue;
		for (int i = 0; i < G[v].size(); ++i) {
			edge e = G[v][i];
			if (d[e.to] > d[v] + e.cost) {
				d[e.to] = d[v] + e.cost;
				que.push(P(d[e.to], e.to));
			}
		}
	}
	return d[g];
}

bool check(int a, int b) {
	if (G[a].empty())
		return false;
	else {
		for (int i = 0; i < G[a].size(); ++i) {
			if (G[a][i].to == b)
				return true;
		}
	}
	return false;
}



int main() {
	while (1) {
		int f;
		int c, d, e;
		std::cin >> n >> k;
		if (n == 0 && k == 0)
			break;
		for (int i = 0; i < k; ++i) {
			std::cin >> f;
			if (f == 0) {
				std::cin >> c >> d;
				--c;
				--d;
				int res = dijkstra(c, d);
				if (res == INF)
					res = -1;
				std::cout << res << std::endl;
			}
			else {
				std::cin >> c >> d >> e;
				--c;
				--d;
				if (check(c, d)) {
					for (int i = 0; i < G[c].size(); ++i) {
						if (G[c][i].to == d&&G[c][i].cost>e) {
							G[c][i].cost = e;
							for (int j = 0; j < G[d].size(); ++j) {
								if (G[d][j].to == c)
									G[d][j].cost = e;
							}
						}
					}
				}
				else {
					G[c].push_back(edge(d, e));
					G[d].push_back(edge(c, e));
				}
			}
		}
	}
	return 0;
}

Compiler output:
In file included from /usr/include/c++/14/queue:66,
                 from a.cc:2:
/usr/include/c++/14/bits/stl_queue.h: In instantiation of 'class std::priority_queue<std::pair<int, int>, std::vector<std::pair<int, int> >, std::greater<std::pair<int, int> >()>':
a.cc:22:60:   required from here
   22 |         std::priority_queue<P, std::vector<P>, std::greater<P>()> que;
      |                                                                   ^~~
/usr/include/c++/14/bits/stl_queue.h:538:18: error: data member 'std::priority_queue<std::pair<int, int>, std::vector<std::pair<int, int> >, std::greater<std::pair<int, int> >()>::comp' invalidly declared function type
  538 |       _Compare   comp;
      |                  ^~~~
a.cc: In function 'int dijkstra(int, int)':
a.cc:22:67: error: no matching function for call to 'std::priority_queue<std::pair<int, int>, std::vector<std::pair<int, int> >, std::greater<std::pair<int, int> >()>::priority_queue()'
   22 |         std::priority_queue<P, std::vector<P>, std::greater<P>()> que;
      |                                                                   ^~~
/usr/include/c++/14/bits/stl_queue.h:691:9: note: candidate: 'template<class _InputIterator, class _Alloc, class _Requires> std::priority_queue<_Tp, _Sequence, _Compare>::priority_queue(_InputIterator, _InputIterator, const _Compare&, _Sequence&&, const _Alloc&) [with _Alloc = _InputIterator; _Requires = _Alloc; _Tp = std::pair<int, int>; _Sequence = std::vector<std::pair<int, int> >; _Compare = std::greater<std::pair<int, int> >()]'
  691 |         priority_queue(_InputIterator __first, _InputIterator __last,
      |         ^~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_queue.h:691:9: note:   candidate expects 5 arguments, 0 provided
/usr/include/c++/14/bits/stl_queue.h:679:9: note: candidate: 'template<class _InputIterator, class _Alloc, class, class _Requires> std::priority_queue<_Tp, _Sequence, _Compare>::priority_queue(_InputIterator, _InputIterator, const _Compare&, const _Sequence&, const _Alloc&) [with _Alloc = _InputIterator; <template-parameter-2-3> = _Alloc; _Requires = <template-parameter-1-3>; _Tp = std::pair<int, int>; _Sequence = std::vector<std::pair<int, int> >; _Compare = std::greater<std::pair<int, int> >()]'
  679 |         priority_queue(_InputIterator __first, _InputIterator __last,
      |         ^~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_queue.h:679:9: note:   candidate expects 5 arguments, 0 provided
/usr/include/c++/14/bits/stl_queue.h:671:9: note: candidate: 'template<class _InputIterator, class _Alloc, class, class _Requires> std::priority_queue<_Tp, _Sequence, _Compare>::priority_queue(_InputIterator, _InputIterator, const _Compare&, const _Alloc&) [with _Alloc = _InputIterator; <template-parameter-2-3> = _Alloc; _Requires = <template-parameter-1-3>; _Tp = std::pair<int, int>; _Sequence = std::vector<std::pair<int, int> >; _Compare = std::greater<std::pair<int, int> >()]'
  671 |         priority_queue(_InputIterator __first, _InputIterator __last,
      |         ^~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_queue.h:671:9: note:   candidate expects 4 arguments, 0 provided
/usr/include/c++/14/bits/stl_queue.h:663:9: note: candidate: 'template<class _InputIterator, class _Alloc, class, class _Requires> std::priority_queue<_Tp, _Sequence, _Compare>::priority_queue(_InputIterator, _InputIterator, const _Alloc&) [with _Alloc = _InputIterator; <template-parameter-2-3> = _Alloc; _Requires = <template-parameter-1-3>; _Tp = std::pair<int, int>; _Sequence = std::vector<std::pair<int, int> >; _Compare = std::greater<std::pair<int, int> >()]'
  663 |         priority_queue(_InputIterator __first, _InputIterator __last,
      |         ^~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_queue.h:663:9: note:   candidate expects 3 arguments, 0 provided
/usr/include/c++/14/bits/stl_queue.h:649:9: note: candidate: 'template<class _InputIterator, class> std::priority_queue<_Tp, _Sequence, _Compare>::priority_queue(_InputIterator, _InputIterator, const _Compare&, _Sequence&&) [with <template-parameter-2-2> = _InputIterator; _Tp = std::pair<int, int>; _Sequence = std::vector<std::pair<int, int> >; _Compare = std::greater<std::pair<int, int> >()]'
  649 |         priority_queue(_InputIterator __first, _InputIterator __last,
      |         ^~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_queue.h:649:9: note:   candidate expects 4 arguments, 0 provided
/usr/include/c++/14/bits/stl_queue.h:638:9: note: candidate: 'template<class _InputIterator, class> std::priority_queue<_Tp, _Sequence, _Compare>::priority_queue(_InputIterator, _InputIterator, const _Compare&, const _Sequence&) [with <template-parameter-2-2> = _InputIterator; _Tp = std::pair<int, int>; _Sequence = std::vector<std::pair<int, int> >; _Compare = std::greater<std::pair<int, int> >()]'
  638 |         priority_queue(_InputIterator __first, _InputIterator __last,
      |         ^~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_queue.h:638:9: note:   candidate expects 4 arguments, 0 provided
/usr/include/c++/14/bits/stl_queue.h:629:9: note: candidate: 'template<class _InputIterator, class> std::priority_queue<_Tp, _Sequence, _Compare>::priority_queue(_InputIterator, _InputIterator, const _Compare&) [with <template-parameter-2-2> = _InputIterator; _Tp = std::pair<int, int>; _Sequence = std::vector<std::pair<int, int> >; _Compare = std::greater<std::pair<int, int> >()]'
  629 |         priority_queue(_InputIterator __first, _InputIterator __last,
      |         ^~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_queue.h:629:9: note:   candidate expects 2 arguments, 0 provided
/usr/include/c++/14/bits/stl_queue.h:594:9: note: candidate: 'template<class _Alloc, class _Requires> std::priority_queue<_Tp, _Sequence, _Compare>::priority_queue(std::priority_queue<_Tp, _Sequence, _Compare>&&, const _Alloc&) [with _Requires = _Alloc; _Tp = std::pair<int, int>; _Sequence = std::vector<std::pair<int, int> >; _Compare = std::greater<std::pair<int, int> >()]'
  594 |         priority_queue(priority_queue&& __q, const _Alloc& __a)
      |         ^~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_queue.h:594:9: note:   candidate expects 2 arguments, 0 provided
/usr/include/c++/14/bits/stl_queue.h:590:9: note: candidate: 'template<class _Alloc, class _Requires> std::priority_queue<_Tp, _Sequence, _Compare>::priority_queue(const std::priority_queue<_Tp, _Sequence, _Compare>&, const _Alloc&) [with _Requires = _Alloc; _Tp = std::pair<int, int>; _Sequence = std::vector<std::pair<int, int> >; _Compare = std::greater<std::pair<int, int> >()]'
  590 |         priority_queue(const priority_queue& __q, const _Alloc& __a)
      |         ^~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_queue.h:590:9: note:   candidate expects 2 arguments, 0 provided
/usr/include/c++/14/bits/stl_queue.h:585:9: note: candidate: 'template<class _Alloc, class _Requires> std::priority_queue<_Tp, _Sequence, _Compare>::priority_queue(const _Compare&, _Sequence&&, const _Alloc&) [with _Requires = _Alloc; _Tp = std::pair<int, int>; _Sequence = std::vector<std::pair<int, int> >; _Compare = std::greater<std::pair<int, int> >()]'
  585 |         priority_queue(const _Compare& __x, _Sequence&& __c, const _Alloc& __a)
      |         ^~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_queue.h:585:9: note:   candidate expects 3 arguments, 0 provided
/usr/include/c++/14/bits/stl_queue.h:579:9: note: candidate: 'template<class _Alloc, class _Requires> std::priority_queue<_Tp, _Sequence, _Compare>::priority_queue(const _Compare&, const _Sequence&, const _Alloc&) [with _Requires = _Alloc; _Tp = std::pair<int, int>; _Sequence = std::vector<std::pair<int, int> >; _Compare = std::greater<std::pair<int, int> >()]'
  579 |         priority_queue(const _Compare& __x, const _Sequence& __c,
      |         ^~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_queue.h:579:9: note:   candidate expects 3 arguments, 0 provided
/usr/include/c++/14/bits/stl_queue.h:573:9: note: candidate: 'template<class _Alloc, class _Requires> std::priority_queue<_Tp, _Sequence, _Compare>::priority_queue(const _Compare&, const _Alloc&) [with _Requires = _Alloc; _Tp = std::pair<int, int>; _Sequence = std::vector<std::pair<int, int> >; _Compare = std::greater<std::pair<int, int> >()]'
  573 |         priority_queue(const _Compare& __x, const _Alloc& __a)
      |         ^~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_queue.h:573:9: note:   candidate expects 2 arguments, 0 provided
/usr/include/c++/14/bits/stl_queue.h:569:9: note: candidate: 'template<class _Alloc, class _Requires> std::priority_queue<_Tp, _Sequence, _Compare>::priority_queue(const _Alloc&) [with _Requires = _Alloc; _Tp = std::pair<int, int>; _Sequence = std::vector<std::pair<int, int> >; _Compare = std::greater<std::pair<int, int> >()]'
  569 |         priority_queue(const _Alloc& __a)
      |         ^~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_queue.h:569:9: note:   candidate expects 1 argument, 0 provided
/usr/include/c++/14/bits/stl_queue.h:554:9: note: candidate: 'template<class _Seq, class _Requires> std::priority_queue<_Tp, _Sequence, _Compare>::priority_queue() [with _Requires = _Seq; _Tp = std::pair<int, int>; _Sequence = std::vector<std::pair<int, int> >; _Compare = std::greater<std::pair<int, int> >()]'
  554 |         priority_queue()
      |         ^~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_queue.h:554:9: note:   template argument deduction/substitution failed:
/usr/include/c++/14/bits/stl_queue.h:551:43: error: no type named 'type' in 'struct std::enable_if<false, void>'
  551 |       template<typename _Seq = _Sequence, typename _Requires = typename
      |                                           ^~~~~~~~
/usr/include/c++/14/bits/stl_queue.h:563:7: note: candidate: 'std::priority_queue<_Tp, _Sequence, _Compare>::priority_queue(const _Compare&, _Sequence&&) [with _Tp = std::pair<int, int>; _Sequence = std::vector<std::pair<int, int> >; _Compare = std::greater<std::pair<int, int> >()]'
  563 |       priority_queue(const _Compare& __x, _Sequence&& __s = _Sequence())
      |       ^~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_queue.h:563:7: note:   candidate expects 2 arguments, 0 provided
/usr/include/c++/14/bits/stl_queue.h:558:7: note: candidate: 'std: