Language: C++

using namespace std;
int n, m, x, y, c, cnt;
int d[500020];
vector<pair<int, int> > a[500020];
map<int, int> g[100020];
deque<int> q;
int get(int x, int y) {
	if (g[x].count(y)) {
		return g[x][y];
	}
	return g[x][y] = ++cnt;
}
void add(int x, int y, int z) {
	a[x].push_back(make_pair(y, z));
	a[y].push_back(make_pair(x, z));
}
int main() {
	scanf("%d%d", &n, &m);
	for (int i = 1; i <= n; i++) {
		get(i, 0);
	}
	for (int i = 0; i < m; i++) {
		scanf("%d%d%d", &x, &y, &c);
		int x0 = get(x, 0), xc = get(x, c);
		int y0 = get(y, 0), yc = get(y, c);
		add(xc, yc, 0);
		add(x0, yc, 1);
		add(xc, y0, 1);
	}
	memset(d, -1, sizeof d);
	d[1] = 0;
	q.push_back(1);
	while (q.size()) {
		int u = q.back();
		q.pop_back();
		for (pair<int, int> i: a[u]) {
			if (d[i.first] == -1 || d[i.first] > d[u] + i.second) {
				d[i.first] = d[u] + i.second;
				if (i.second == 1) {
					q.push_front(i.first);
				} else {
					q.push_back(i.first);
				}
			}
		}
	}
	printf("%d\n", d[n] >> 1);
	return 0;
}

Compiler output:
a.cc:4:1: error: 'vector' does not name a type
    4 | vector<pair<int, int> > a[500020];
      | ^~~~~~
a.cc:5:1: error: 'map' does not name a type
    5 | map<int, int> g[100020];
      | ^~~
a.cc:6:1: error: 'deque' does not name a type
    6 | deque<int> q;
      | ^~~~~
a.cc: In function 'int get(int, int)':
a.cc:8:13: error: 'g' was not declared in this scope
    8 |         if (g[x].count(y)) {
      |             ^
a.cc:11:16: error: 'g' was not declared in this scope
   11 |         return g[x][y] = ++cnt;
      |                ^
a.cc: In function 'void add(int, int, int)':
a.cc:14:9: error: 'a' was not declared in this scope
   14 |         a[x].push_back(make_pair(y, z));
      |         ^
a.cc:14:24: error: 'make_pair' was not declared in this scope
   14 |         a[x].push_back(make_pair(y, z));
      |                        ^~~~~~~~~
a.cc:1:1: note: 'std::make_pair' is defined in header '<utility>'; this is probably fixable by adding '#include <utility>'
  +++ |+#include <utility>
    1 | using namespace std;
a.cc: In function 'int main()':
a.cc:18:9: error: 'scanf' was not declared in this scope
   18 |         scanf("%d%d", &n, &m);
      |         ^~~~~
a.cc:30:9: error: 'memset' was not declared in this scope
   30 |         memset(d, -1, sizeof d);
      |         ^~~~~~
a.cc:1:1: note: 'memset' is defined in header '<cstring>'; this is probably fixable by adding '#include <cstring>'
  +++ |+#include <cstring>
    1 | using namespace std;
a.cc:32:9: error: 'q' was not declared in this scope
   32 |         q.push_back(1);
      |         ^
a.cc:36:22: error: 'pair' was not declared in this scope
   36 |                 for (pair<int, int> i: a[u]) {
      |                      ^~~~
a.cc:36:22: note: 'std::pair' is defined in header '<utility>'; this is probably fixable by adding '#include <utility>'
a.cc:36:27: error: expected primary-expression before 'int'
   36 |                 for (pair<int, int> i: a[u]) {
      |                           ^~~
a.cc:46:9: error: expected primary-expression before '}' token
   46 |         }
      |         ^
a.cc:45:18: error: expected ';' before '}' token
   45 |                 }
      |                  ^
      |                  ;
   46 |         }
      |         ~         
a.cc:46:9: error: expected primary-expression before '}' token
   46 |         }
      |         ^
a.cc:45:18: error: expected ')' before '}' token
   45 |                 }
      |                  ^
      |                  )
   46 |         }
      |         ~         
a.cc:36:21: note: to match this '('
   36 |                 for (pair<int, int> i: a[u]) {
      |                     ^
a.cc:46:9: error: expected primary-expression before '}' token
   46 |         }
      |         ^
a.cc:47:9: error: 'printf' was not declared in this scope
   47 |         printf("%d\n", d[n] >> 1);
      |         ^~~~~~
a.cc:1:1: note: 'printf' is defined in header '<cstdio>'; this is probably fixable by adding '#include <cstdio>'
  +++ |+#include <cstdio>
    1 | using namespace std;