Language: C++

#include <bits/stdc++.h>
using namespace std;
#define f first
#define s second
#define pb push_back
#define reset(a,b) memset(a,b,sizeof a);
#define ALL(x) x.begin(),x.end()
#define debug(x) cout<<#x<<" = "<<(x)<<endl
#define sz(x) (int)(x.size())
#define lt(x) (int)(x.length())
#define MOD 1000000007 
#define mx 1000003

int n, m, p, q, c, dist[mx], idx, kota[mx], company[mx];
set<int> daftar[mx];
vector<pair<int, int>> g[mx];

map<pair<int, int>, int> indeks;

int getindeks(int i, int j){
	if(indeks.count({i, j}))
		return indeks[{i, j}];
	kota[idx] = i;
	company[idx] = j;
	indeks[{i, j}] = idx++;
	return idx - 1;
}

int main(){
	cin >> n >> m;
	for(int i = 0; i < m; i++){
		cin >> p >> q >> c;
		p -= 1, q -= 1, c -= 1;
		g[p].pb({c, q});
		g[q].pb({c, q});
		daftar[p].insert(c);
		daftar[q].insert(c);
	}
	for(int i = 0; i < n; i++)
		sort(ALL(g[i]));
	priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> pq;
	reset(dist, -1);
	pq.push({0, getindeks(0, -1)});
	dist[getindeks(0, -1)] = 0;
	while(!pq.empty()){
		int now, dis;
		tie(dis, now) = pq.top();
		pq.pop();
		// debug(kota[now]);
		// debug(company[now]);
		// debug(dis);
		if(company[now] == -1){
			for(int i : daftar[kota[now]]){
				if(dist[getindeks(kota[now], i)] == -1 || dist[getindeks(kota[now], i)] > dis + 1){
					dist[getindeks(kota[now], i)] = dis + 1;
					pq.push({dis + 1, getindeks(kota[now], i)});
				}
			}
			continue;
		}
		// int it1, it2;
		int it1 = lower_bound(ALL(g[kota[now]]), make_pair(company[now], -1), [&](pair<int, int> x, pair<int, int> y){
			return x.f < y.f;
		}) - g[kota[now]].begin();
		int it2 = upper_bound(ALL(g[kota[now]]), make_pair(company[now], 1e9), [&](pair<int, int> x, pair<int, int> y){
			return x.f < y.f;
		}) - g[kota[now]].begin();
		for(int x = it1; x < it2; x++){
			auto i = g[kota[now]][x];
			assert(company[now] == i.f)
			int cost = 0;
			if(dist[getindeks(i.s, i.f)] == -1 || dist[getindeks(i.s, i.f)] > dis + cost){
				dist[getindeks(i.s, i.f)] = dis + cost;
				pq.push({dis + cost, getindeks(i.s, i.f)});
			}	
		}
		if(dist[getindeks(kota[now], -1)] == -1 || dist[getindeks(kota[now], -1)] > dis){
			dist[getindeks(kota[now], -1)] = dis;
			pq.push({dis, getindeks(kota[now], -1)});
		}
	}
	int jaw = dist[getindeks(n - 1, -1)];
	// for(int i : daftar[n - 1]){
	// 	if(dist[getindeks(n - 1, i)] == -1)
	// 		continue;
	// 	jaw = min(jaw, dist[getindeks(n - 1, i)]);
	// }
	if(jaw == 1e9)
		jaw = -1;
	cout << jaw << endl;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:71:25: error: expected ';' before 'int'
   71 |                         int cost = 0;
      |                         ^~~
a.cc:72:97: error: 'cost' was not declared in this scope; did you mean 'cosl'?
   72 |                         if(dist[getindeks(i.s, i.f)] == -1 || dist[getindeks(i.s, i.f)] > dis + cost){
      |                                                                                                 ^~~~
      |                                                                                                 cosl
a.cc:74:40: 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> > >::push(<brace-enclosed initializer list>)'
   74 |                                 pq.push({dis + cost, getindeks(i.s, i.f)});
      |                                 ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/14/queue:66,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:157,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_queue.h:736:7: note: candidate: 'void std::priority_queue<_Tp, _Sequence, _Compare>::push(const value_type&) [with _Tp = std::pair<int, int>; _Sequence = std::vector<std::pair<int, int> >; _Compare = std::greater<std::pair<int, int> >; value_type = std::pair<int, int>]'
  736 |       push(const value_type& __x)
      |       ^~~~
/usr/include/c++/14/bits/stl_queue.h:736:30: note:   no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'const std::priority_queue<std::pair<int, int>, std::vector<std::pair<int, int> >, std::greater<std::pair<int, int> > >::value_type&' {aka 'const std::pair<int, int>&'}
  736 |       push(const value_type& __x)
      |            ~~~~~~~~~~~~~~~~~~^~~
/usr/include/c++/14/bits/stl_queue.h:744:7: note: candidate: 'void std::priority_queue<_Tp, _Sequence, _Compare>::push(value_type&&) [with _Tp = std::pair<int, int>; _Sequence = std::vector<std::pair<int, int> >; _Compare = std::greater<std::pair<int, int> >; value_type = std::pair<int, int>]'
  744 |       push(value_type&& __x)
      |       ^~~~
/usr/include/c++/14/bits/stl_queue.h:744:25: note:   no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'std::priority_queue<std::pair<int, int>, std::vector<std::pair<int, int> >, std::greater<std::pair<int, int> > >::value_type&&' {aka 'std::pair<int, int>&&'}
  744 |       push(value_type&& __x)
      |            ~~~~~~~~~~~~~^~~