Language: C++

using System;
using System.Collections.Generic;
using System.Linq;


 
struct Z2 {
	public int x, y;
	public Z2(int x, int y){
		this.x = x; this.y = y;
	}
}

struct Z3 {
	public int x;
	public Z2 z;
	public Z3(int x, Z2 z){
		this.x = x; this.z = z;
	}
}
 
public class A {
	int N,M;
	Dictionary<Z2,List<Z2>> edges;
    
	
	public A(){
		edges = new Dictionary<Z2,List<Z2>>();
	}
	
	string[] Rs(){
		return Console.ReadLine().Split(' ');
	}
	public void run(){
		string[] str = Rs();
		N = int.Parse(str[0]); M = int.Parse(str[1]);
		for(int i=0;i<N;i++){
            edges.Add(new Z2(i,-1), new List<Z2>());
        }
        
        Action<Z2,Z2> f = (p1,p2) => {
            if(edges.ContainsKey(p1)){
                edges[p1].Add(p2);
            } else {
                var l = new List<Z2>(); l.Add(p2);
                edges.Add( p1,  l);
            }
            Z2 ne = new Z2(p1.x, -1);
            edges[p1].Add(ne);
            edges[ne].Add(new Z2(p2.x,-1));
        };
        
        for(int i=0;i<M;i++){
			int[] inp = Rs().Select( x => int.Parse(x)-1 ).ToArray();
            Z2 e0 = new Z2(inp[0], inp[2]), e1 = new Z2(inp[1], inp[2]);
            f(e0,e1);
            f(e1,e0);
        }
        
        Dictionary<Z2, int> dis = new Dictionary<Z2,int>();
		LinkedList<Z3> que = new LinkedList<Z3>();
		
		que.AddLast(new Z3(0, new Z2(0,-1)) ); 
		dis.Add( new Z2(0, -1), 0);
        Z2 end = new Z2(N-1,-1);
        
		while(que.Count!=0){
			Z3 n = que.First(); que.RemoveFirst();
			Z2 nz = n.z;
			if(dis.ContainsKey(end)){ 
				Console.WriteLine(dis[end]);
				return;
			}
			if(n.x > dis[nz]) continue;
            foreach(Z2 e in edges[nz]){
					if(nz.y==-1){
						int nv = dis[nz] + 1;
	                    if(!dis.ContainsKey(e)){
							dis.Add(e, nv);
							que.AddLast(new Z3(nv, e));
	                    } else if(nv < dis[e]){
							dis[e] = nv;
							que.AddLast(new Z3(nv, e));
						}
					} else {
						if(!dis.ContainsKey(e)){
							dis.Add(e, dis[nz]);
							que.AddFirst(new Z3(dis[nz], e));
	                    } else if(dis[nz] < dis[e]){
							dis[e] = dis[nz];
							que.AddFirst(new Z3(dis[nz], e));
						}
					}
            }
        }
		Console.WriteLine("-1");
	}
}
 
public class Program {
	static void Main(string[] args){
		A a = new A();
		a.run();
	}
}

Compiler output:
a.cc:1:7: error: expected nested-name-specifier before 'System'
    1 | using System;
      |       ^~~~~~
a.cc:2:7: error: expected nested-name-specifier before 'System'
    2 | using System.Collections.Generic;
      |       ^~~~~~
a.cc:3:7: error: expected nested-name-specifier before 'System'
    3 | using System.Linq;
      |       ^~~~~~
a.cc:8:15: error: expected ':' before 'int'
    8 |         public int x, y;
      |               ^~~~
      |               :
a.cc:9:15: error: expected ':' before 'Z2'
    9 |         public Z2(int x, int y){
      |               ^~~
      |               :
a.cc:12:2: error: expected ';' after struct definition
   12 | }
      |  ^
      |  ;
a.cc: In constructor 'Z2::Z2(int, int)':
a.cc:10:22: error: request for member 'x' in '(Z2*)this', which is of pointer type 'Z2*' (maybe you meant to use '->' ?)
   10 |                 this.x = x; this.y = y;
      |                      ^
a.cc:10:34: error: request for member 'y' in '(Z2*)this', which is of pointer type 'Z2*' (maybe you meant to use '->' ?)
   10 |                 this.x = x; this.y = y;
      |                                  ^
a.cc: At global scope:
a.cc:15:15: error: expected ':' before 'int'
   15 |         public int x;
      |               ^~~~
      |               :
a.cc:16:15: error: expected ':' before 'Z2'
   16 |         public Z2 z;
      |               ^~~
      |               :
a.cc:17:15: error: expected ':' before 'Z3'
   17 |         public Z3(int x, Z2 z){
      |               ^~~
      |               :
a.cc:20:2: error: expected ';' after struct definition
   20 | }
      |  ^
      |  ;
a.cc: In constructor 'Z3::Z3(int, Z2)':
a.cc:17:31: error: no matching function for call to 'Z2::Z2()'
   17 |         public Z3(int x, Z2 z){
      |                               ^
a.cc:9:16: note: candidate: 'Z2::Z2(int, int)'
    9 |         public Z2(int x, int y){
      |                ^~
a.cc:9:16: note:   candidate expects 2 arguments, 0 provided
a.cc:7:8: note: candidate: 'constexpr Z2::Z2(const Z2&)'
    7 | struct Z2 {
      |        ^~
a.cc:7:8: note:   candidate expects 1 argument, 0 provided
a.cc:7:8: note: candidate: 'constexpr Z2::Z2(Z2&&)'
a.cc:7:8: note:   candidate expects 1 argument, 0 provided
a.cc:18:22: error: request for member 'x' in '(Z3*)this', which is of pointer type 'Z3*' (maybe you meant to use '->' ?)
   18 |                 this.x = x; this.z = z;
      |                      ^
a.cc:18:34: error: request for member 'z' in '(Z3*)this', which is of pointer type 'Z3*' (maybe you meant to use '->' ?)
   18 |                 this.x = x; this.z = z;
      |                                  ^
a.cc: At global scope:
a.cc:22:1: error: expected unqualified-id before 'public'
   22 | public class A {
      | ^~~~~~
a.cc:100:1: error: expected unqualified-id before 'public'
  100 | public class Program {
      | ^~~~~~