Language: C++

#include <iostream>
#include <vector>
#include <set>
#include <unordered_set>
#include <iterator>
#include <map>
#include <unordered_map>
#include <queue>
using namespace std;
#define Inf 1073741789

int N, M, V;
int* us, vs, xs;
unordered_set<int> dead;
// vector<vector<int> > es;
vector<int>* es;
// const int Inf = 1073741789;

int* dijkstra(int from)
{
	auto d = new int[V];
	// vector<int> d(V);
	// for (int i = 0; i < V; i++) d.push_back(Inf);
	for (int i = 0; i < V; i++) d[i] = Inf;
	priority_queue<pair<int, int> > queue;
	d[from] = 0;
	queue.emplace(from, 0);
	while (queue.size() > 0)
	{
		auto p = queue.top(); queue.pop();
		int u = p.first, tmp = d[u] + dead.count(u);
		if (d[u] < -p.second) continue;
		for (auto v : es[u]) if (d[v] > tmp) queue.emplace(v, -(d[v] = tmp));
	}
	return d;
}

int main()
{
	cin >> N >> M;
	//vector<set<int> > cs(N);
	auto cs = new set<int>[N];
	for (int i = 0; i < N; i++) cs[i].insert(-1);
	// for (int i = 0; i < N; i++)
	// {
	// 	cs.push_back(set<int>());
	// 	cs[i].insert(-1);
	// }
	us = new int[M];
	vs = new int[M];
	xs = new int[M];
	for (int i = 0; i < M; i++)
	{
		int a, b, c;
		cin >> a >> b >> c;
		us[i] = --a;
		vs[i] = --b;
		xs[i] = --c;
		cs[a].insert(c);
		cs[b].insert(c);
	}
	// vector<int> sep;
	auto sep = new int[N + 1];
	// sep.push_back(0);
	sep[0] = 0;
	for (int i = 0; i < N; i++) sep[i + 1] = sep[i] + cs[i].size();
	// for (int i = 0; i < N; i++) sep.push_back(sep[i] + cs[i].size());
	dead.insert(sep, sep + N + 1);
	// dead.insert(sep.begin(), sep.end());
	V = sep[N];
	// vector<map<int, int> > index;
	auto index = new map<int, int>[N];
	for (int i = 0, j = 0; i < N; i++) for (auto c : cs[i]) index[i].emplace(c, j++);
	// for (int i = 0, j = 0; i < N; i++)
	// 	{
	// 		index.push_back(map<int, int>());
	// 		for (auto c : cs[i]) index[i].emplace(c, j++);
	// 	}
	es = new vector<int>[V];
	// for (int i = 0; i < V; i++) es.push_back(vector<int>());
	for (int i = 0; i < M; i++)
		{
			int a = us[i], b = vs[i], c = xs[i], u = index[a][c], v = index[b][c];
			es[u].push_back(v);
			es[v].push_back(u);
		}
	for (int i = 0; i < N; i++)
		for (int j = sep[i] + 1; j < sep[i + 1]; j++)
		{
			es[j].push_back(sep[i]);
			es[sep[i]].push_back(j);
		}
	auto d = dijkstra(0);
	cout << (d[sep[N - 1]] == Inf ? -1 : d[sep[N - 1]]) << endl;
	delete[] d;
	delete[] cs;
	delete[] sep;
	delete[] index;
	delete[] us;
	delete[] vs;
	delete[] xs;
	delete[] es;
	return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:50:14: error: invalid conversion from 'int*' to 'int' [-fpermissive]
   50 |         vs = new int[M];
      |              ^~~~~~~~~~
      |              |
      |              int*
a.cc:51:14: error: invalid conversion from 'int*' to 'int' [-fpermissive]
   51 |         xs = new int[M];
      |              ^~~~~~~~~~
      |              |
      |              int*
a.cc:57:19: error: invalid types 'int[int]' for array subscript
   57 |                 vs[i] = --b;
      |                   ^
a.cc:58:19: error: invalid types 'int[int]' for array subscript
   58 |                 xs[i] = --c;
      |                   ^
a.cc:83:46: error: invalid types 'int[int]' for array subscript
   83 |                         int a = us[i], b = vs[i], c = xs[i], u = index[a][c], v = index[b][c];
      |                                              ^
a.cc:84:28: error: 'u' was not declared in this scope
   84 |                         es[u].push_back(v);
      |                            ^
a.cc:84:41: error: 'v' was not declared in this scope
   84 |                         es[u].push_back(v);
      |                                         ^
a.cc:100:18: error: type 'int' argument given to 'delete', expected pointer
  100 |         delete[] vs;
      |                  ^~
a.cc:101:18: error: type 'int' argument given to 'delete', expected pointer
  101 |         delete[] xs;
      |                  ^~