Language: C++

#include <iostream>
#include <vector>
#include <queue>
#include <functional>
using namespace std;

struct edge { int to, cost; edge(int _to, int _cost) {to = _to; cost=_cost;} };
typedef pair<int, int> pii;
int INF = 1012012012;

vector<edge> e[100];

int ds(int s, int g) {

	int field[100];
	priority_queue<pii, vector<pii>, greater<pii> > q;
	
	for(int i = 0; i < 100; i++)
		field[i] = INF;
	field[s-1] = 0;
	
	q.push(pii(0, s));
	
	while(!q.empty()) {
		pii p = q.top(); q.pop();
		int m = p.second;
		if(field[m] < p.first) continue;
		for(int i = 0; i < (int)e[m].size(); i++) {
			edge ee = e[m][i];
			if(field[ee.to] > field[m] + ee.cost) {
				field[ee.to] = field[m] + ee.cost;
				q.push(pii(field[ee.to], ee.to));
			}
		}
	}

	return (field[g] == INF) ? -1 : field[g];
	
}

int main() {

	int n, k;
	int a, b, c, d, e, f;
	
	cin >> n >> k;
	
	while(k--, k != -1) {
		cin >> f;
		if(f == 0) {
			cin >> a >> b;
			cout << ds(a-1, b-1) << endl;
		} else {
			cin >> c >> d >> e;
			if(e[c-1].empty()) {
				e[c-1].push_back(edge(d-1, e));
			} else {
				bool add = true;
				for(int i = 0; i < e[c-1].size(); i++) {
					if(e[c-1][i].to == d-1) {
						add = false;
						if(e[c-1][i].cost > e) {
							e[c-1][i].cost = e;
						}
						break;
					}
				}
				if(add) e[c-1].pushback(edge(d-1, e));
			}
			if(e[d-1].empty()) {
				e[d-1].push_back(edge(c-1, e));
			} else {
				bool add = true;
				for(int i = 0; i < e[d-1].size(); i++) {
					if(e[d-1][i].to == c-1) {
						add = false;
						if(e[d-1][i].cost > e) {
							e[d-1][i].cost = e;
						}
						break;
					}
				}
				if(add) e[d-1].pushback(edge(c-1, e));
			}
		}
	}

	return 0;

}

Compiler output:
a.cc: In function 'int main()':
a.cc:55:29: error: invalid types 'int[int]' for array subscript
   55 |                         if(e[c-1].empty()) {
      |                             ^
a.cc:56:34: error: invalid types 'int[int]' for array subscript
   56 |                                 e[c-1].push_back(edge(d-1, e));
      |                                  ^
a.cc:59:53: error: invalid types 'int[int]' for array subscript
   59 |                                 for(int i = 0; i < e[c-1].size(); i++) {
      |                                                     ^
a.cc:60:45: error: invalid types 'int[int]' for array subscript
   60 |                                         if(e[c-1][i].to == d-1) {
      |                                             ^
a.cc:62:53: error: invalid types 'int[int]' for array subscript
   62 |                                                 if(e[c-1][i].cost > e) {
      |                                                     ^
a.cc:63:58: error: invalid types 'int[int]' for array subscript
   63 |                                                         e[c-1][i].cost = e;
      |                                                          ^
a.cc:68:42: error: invalid types 'int[int]' for array subscript
   68 |                                 if(add) e[c-1].pushback(edge(d-1, e));
      |                                          ^
a.cc:70:29: error: invalid types 'int[int]' for array subscript
   70 |                         if(e[d-1].empty()) {
      |                             ^
a.cc:71:34: error: invalid types 'int[int]' for array subscript
   71 |                                 e[d-1].push_back(edge(c-1, e));
      |                                  ^
a.cc:74:53: error: invalid types 'int[int]' for array subscript
   74 |                                 for(int i = 0; i < e[d-1].size(); i++) {
      |                                                     ^
a.cc:75:45: error: invalid types 'int[int]' for array subscript
   75 |                                         if(e[d-1][i].to == c-1) {
      |                                             ^
a.cc:77:53: error: invalid types 'int[int]' for array subscript
   77 |                                                 if(e[d-1][i].cost > e) {
      |                                                     ^
a.cc:78:58: error: invalid types 'int[int]' for array subscript
   78 |                                                         e[d-1][i].cost = e;
      |                                                          ^
a.cc:83:42: error: invalid types 'int[int]' for array subscript
   83 |                                 if(add) e[d-1].pushback(edge(c-1, e));
      |                                          ^