Language: C++

#include<bits/stdc++.h>
#define ll long long
#define mp make_pair
#define pb push_back
#define pii pair<int,int>
#define A first
#define B second
#define db double
#define lowbit(p) (p&(-p))
using namespace std;
void read(int &x){
	x=0; char c=getchar(); int p=1;
	for (;c<48;c=getchar())if (c=='-')p=-1;
	for (;c>47;c=getchar())x=(x<<1)+(x<<3)+(c^48);
	x*=p;
}
void read(ll &x){
	x=0; char c=getchar(); int p=1;
	for (;c<48;c=getchar())if (c=='-')p=-1;
	for (;c>47;c=getchar())x=(x<<1)+(x<<3)+(c^48);
	x*=p;
}
void Min(int &x,int y){
	if (x>y)x=y;
}
void Max(int &x,int y){
	if (x<y)x=y;
}
void Min(ll &x,ll y){
	if (x>y)x=y;
}
void Max(ll &x,ll y){
	if (x<y)x=y;
}

map< pii,int >id;
#define M 100005
struct ed{
	int x,l,nx;
}e[M*12];
int nx[3*M],dis[3*M],n,m,ecnt=1;
bool mark[3*M];
priority_queue< pii >Q;
void add(int x,int y,int l){
	e[ecnt]=(ed){y,l,nx[x]};
	nx[x]=ecnt++;
}
void dij(int s,int t){
	memset(dis,63,sizeof(dis));
	Q.push(mp(dis[s]=0,s));
	int x;
	for (;!Q.empty();){
		x=Q.top().B; Q.pop();
		if (mark[x])continue;
		mark[x]=1;
		for (int i=nx[x];i;i=e[i].nx){
			if (dis[x]+e[i].l<dis[e[i].x]){
				dis[e[i].x]=dis[x]+e[i].l;
				Q.push(mp(-dis[e[i].x],e[i].x));
			}
		}
	}
	if (mark[t]){
		printf("%d\n",dis[t]);
	}
	else {
		printf("-1\n");
	}
}
int tot;
int get(int x,int y){
	if (id[mp(x,y)])return id[mp(x,y)];
	else return id[mp(x,y)]=++tot;
}
int main(){
	int Caseid;
// 	freopen("4.in","r",stdin);
//	read(Caseid);
	read(n); read(m);	
	int i,x,y,c;
	for (i=1;i<=m;i++){
		read(x); read(y); read(c);
		add(get(x,0),get(x,c),1);
		add(get(x,c),get(y,c),0);
		add(get(y,c),get(y,0),0);
		add(get(y,0),get(y,c),1);
		add(get(x,c),get(x,0),0);
		add(get(y,c),get(x,c),0);
	}
	dij(get(1,0),get(n,0));
	return 0;
}#include<bits/stdc++.h>
#define ll long long
#define mp make_pair
#define pb push_back
#define pii pair<int,int>
#define A first
#define B second
#define db double
#define lowbit(p) (p&(-p))
using namespace std;
void read(int &x){
	x=0; char c=getchar(); int p=1;
	for (;c<48;c=getchar())if (c=='-')p=-1;
	for (;c>47;c=getchar())x=(x<<1)+(x<<3)+(c^48);
	x*=p;
}
void read(ll &x){
	x=0; char c=getchar(); int p=1;
	for (;c<48;c=getchar())if (c=='-')p=-1;
	for (;c>47;c=getchar())x=(x<<1)+(x<<3)+(c^48);
	x*=p;
}
void Min(int &x,int y){
	if (x>y)x=y;
}
void Max(int &x,int y){
	if (x<y)x=y;
}
void Min(ll &x,ll y){
	if (x>y)x=y;
}
void Max(ll &x,ll y){
	if (x<y)x=y;
}

map< pii,int >id;
#define M 200005
struct ed{
	int x,l,nx;
}e[M*6];
int nx[3*M],dis[3*M],n,m,ecnt=1;
bool mark[3*M];
priority_queue< pii >Q;
void add(int x,int y,int l){
	e[ecnt]=(ed){y,l,nx[x]};
	nx[x]=ecnt++;
}
void dij(int s,int t){
	memset(dis,63,sizeof(dis));
	Q.push(mp(dis[s]=0,s));
	int x;
	for (;!Q.empty();){
		x=Q.top().B; Q.pop();
		if (mark[x])continue;
		mark[x]=1;
		if (x==t)break;
		for (int i=nx[x];i;i=e[i].nx){
			if (dis[x]+e[i].l<dis[e[i].x]){
				dis[e[i].x]=dis[x]+e[i].l;
				Q.push(mp(-dis[e[i].x],e[i].x));
			}
		}
	}
	if (mark[t]){
		printf("%d\n",dis[t]);
	}
	else {
		printf("-1\n");
	}
}
int tot;
int get(int x,int y){
	if (id[mp(x,y)])return id[mp(x,y)];
	else return id[mp(x,y)]=++tot;
}
int main(){
	int Caseid;
// 	freopen("4.in","r",stdin);
//	read(Caseid);
	read(n); read(m);	
	int i,x,y,c;
	for (i=1;i<=m;i++){
		read(x); read(y); read(c);
		add(get(x,0),get(x,c),1);
		add(get(x,c),get(y,c),0);
		add(get(y,c),get(y,0),0);
		add(get(y,0),get(y,c),1);
		add(get(y,c),get(x,c),0);
		add(get(x,c),get(x,0),0);
	}
	dij(get(1,0),get(n,0));
	return 0;
}

Compiler output:
a.cc:92:2: error: stray '#' in program
   92 | }#include<bits/stdc++.h>
      |  ^
a.cc:128:9: warning: "M" redefined
  128 | #define M 200005
      |         ^
a.cc:37:9: note: this is the location of the previous definition
   37 | #define M 100005
      |         ^
a.cc:92:3: error: 'include' does not name a type
   92 | }#include<bits/stdc++.h>
      |   ^~~~~~~
a.cc:102:6: error: redefinition of 'void read(int&)'
  102 | void read(int &x){
      |      ^~~~
a.cc:11:6: note: 'void read(int&)' previously defined here
   11 | void read(int &x){
      |      ^~~~
a.cc:108:6: error: redefinition of 'void read(long long int&)'
  108 | void read(ll &x){
      |      ^~~~
a.cc:17:6: note: 'void read(long long int&)' previously defined here
   17 | void read(ll &x){
      |      ^~~~
a.cc:114:6: error: redefinition of 'void Min(int&, int)'
  114 | void Min(int &x,int y){
      |      ^~~
a.cc:23:6: note: 'void Min(int&, int)' previously defined here
   23 | void Min(int &x,int y){
      |      ^~~
a.cc:117:6: error: redefinition of 'void Max(int&, int)'
  117 | void Max(int &x,int y){
      |      ^~~
a.cc:26:6: note: 'void Max(int&, int)' previously defined here
   26 | void Max(int &x,int y){
      |      ^~~
a.cc:120:6: error: redefinition of 'void Min(long long int&, long long int)'
  120 | void Min(ll &x,ll y){
      |      ^~~
a.cc:29:6: note: 'void Min(long long int&, long long int)' previously defined here
   29 | void Min(ll &x,ll y){
      |      ^~~
a.cc:123:6: error: redefinition of 'void Max(long long int&, long long int)'
  123 | void Max(ll &x,ll y){
      |      ^~~
a.cc:32:6: note: 'void Max(long long int&, long long int)' previously defined here
   32 | void Max(ll &x,ll y){
      |      ^~~
a.cc:127:15: error: redefinition of 'std::map<std::pair<int, int>, int> id'
  127 | map< pii,int >id;
      |               ^~
a.cc:36:15: note: 'std::map<std::pair<int, int>, int> id' previously declared here
   36 | map< pii,int >id;
      |               ^~
a.cc:129:8: error: redefinition of 'struct ed'
  129 | struct ed{
      |        ^~
a.cc:38:8: note: previous definition of 'struct ed'
   38 | struct ed{
      |        ^~
a.cc:131:2: error: conflicting declaration 'int e [1200030]'
  131 | }e[M*6];
      |  ^
a.cc:40:2: note: previous declaration as 'ed e [1200060]'
   40 | }e[M*12];
      |  ^
a.cc:132:5: error: conflicting declaration 'int nx [600015]'
  132 | int nx[3*M],dis[3*M],n,m,ecnt=1;
      |     ^~
a.cc:41:5: note: previous declaration as 'int nx [300015]'
   41 | int nx[3*M],dis[3*M],n,m,ecnt=1;
      |     ^~
a.cc:132:13: error: conflicting declaration 'int dis [600015]'
  132 | int nx[3*M],dis[3*M],n,m,ecnt=1;
      |             ^~~
a.cc:41:13: note: previous declaration as 'int dis [300015]'
   41 | int nx[3*M],dis[3*M],n,m,ecnt=1;
      |             ^~~
a.cc:132:22: error: redefinition of 'int n'
  132 | int nx[3*M],dis[3*M],n,m,ecnt=1;
      |                      ^
a.cc:41:22: note: 'int n' previously declared here
   41 | int nx[3*M],dis[3*M],n,m,ecnt=1;
      |                      ^
a.cc:132:24: error: redefinition of 'int m'
  132 | int nx[3*M],dis[3*M],n,m,ecnt=1;
      |                        ^
a.cc:41:24: note: 'int m' previously declared here
   41 | int nx[3*M],dis[3*M],n,m,ecnt=1;
      |                        ^
a.cc:132:26: error: redefinition of 'int ecnt'
  132 | int nx[3*M],dis[3*M],n,m,ecnt=1;
      |                          ^~~~
a.cc:41:26: note: 'int ecnt' previously defined here
   41 | int nx[3*M],dis[3*M],n,m,ecnt=1;
      |                          ^~~~
a.cc:133:6: error: conflicting declaration 'bool mark [600015]'
  133 | bool mark[3*M];
      |      ^~~~
a.cc:42:6: note: previous declaration as 'bool mark [300015]'
   42 | bool mark[3*M];
      |      ^~~~
a.cc:134:22: error: redefinition of 'std::priority_queue<std::pair<int, int> > Q'
  134 | priority_queue< pii >Q;
      |                      ^
a.cc:43:22: note: 'std::priority_queue<std::pair<int, int> > Q' previously declared here
   43 | priority_queue< pii >Q;
      |                      ^
a.cc:135:6: error: redefinition of 'void add(int, int, int)'
  135 | void add(int x,int y,int l){
      |      ^~~
a.cc:44:6: note: 'void add(int, int, int)' previously defined here
   44 | void add(int x,int y,int l){
      |      ^~~
a.cc:139:6: error: redefinition of 'void dij(int, int)'
  139 | void dij(int s,int t){
      |      ^~~
a.cc:48:6: note: 'void dij(int, int)' previously defined here
   48 | void dij(int s,int t){
      |      ^~~
a.cc:162:5: error: redefinition of 'int tot'
  162 | int tot;
      |     ^~~
a.cc:70:5: note: 'int tot' previously declared here
   70 | int tot;
      |     ^~~
a.cc:163:5: error: redefinition of 'int get(int, int)'
  163 | int get(int x,int y){
      |     ^~~
a.cc:71:5: note: 'int get(int, int)' previously defined here
   71 | int get(int x,int y){
      |     ^~~
a.cc:167:5: error: redefinition of 'int main()'
  167 | int main(){
      |     ^~~~
a.cc:75:5: note: 'int main()' previously defined here
   75 | int main(){
      |     ^~~~