Language: C++

use std::collections::*;

#[allow(dead_code)]
fn read<T: std::str::FromStr>() -> T {
    let mut buf = String::new();
    std::io::stdin().read_line(&mut buf).unwrap();
    buf.trim().parse().ok().unwrap()
}

#[allow(dead_code)]
fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    let mut buf = String::new();
    std::io::stdin().read_line(&mut buf).unwrap();
    buf.trim().split_whitespace()
        .map(|x| x.parse().ok().unwrap()).collect()
}

#[derive(Copy, Clone, Debug)]
struct edge(i64, i64, i64);

fn dfs(v : i32, g : &Vec<Vec<edge>>, ok : &mut Vec<i32>) {
    ok[v as usize] = 1;
    for &e in &g[v as usize] {
        if ok[e.2 as usize] == 0 {
            dfs(e.2 as i32, g, ok);
        }
    }
}

fn main() {
    let NMP = read_vec::<i64>();
    let (N, M, P) = (NMP[0], NMP[1], NMP[2]);
    let mut g = Vec::<Vec<edge>>::with_capacity(N as usize);
    let mut ig = Vec::<Vec<edge>>::with_capacity(N as usize);
    let mut ok = Vec::<i32>::with_capacity(N as usize);
    let mut iok = Vec::<i32>::with_capacity(N as usize);
    for i in 0..N {
        g.push(Vec::<edge>::new());
        ig.push(Vec::<edge>::new());
        ok.push(0);
        iok.push(0);
    }
    for i in 0..N {
        let v = read_vec::<i64>();
        g[(v[0]-1) as usize].push(edge(P-v[2], v[0]-1, v[1]-1));
        ig[(v[1]-1) as usize].push(edge(P-v[2], v[1]-1, v[0]-1));
    }
    dfs(0, &g, &mut ok);
    dfs((N-1) as i32, &ig, &mut iok);

    let mut pq = BinaryHeap::<(i64, usize)>::new();
    let mut d = Vec::<i64>::with_capacity(N as usize);
    for i in 0..N {
        d.push(std::i64::MAX);
    }
    d[0] = 0;
    pq.push((0, 0));
    'outer:
    while let Some((dd, vv)) = pq.pop() {
        if dd < d[vv] {
            continue;
        }
        for &e in &g[vv] {
            if ok[e.2 as usize] == 0 || iok[e.2 as usize] == 0 {
                continue;
            }
            if dd + e.0 < d[e.2 as usize] {
                if d[e.2 as usize] != std::i64::MAX {
                    d[(N-1) as usize] = std::i64::MAX;
                    break 'outer;
                }
                d[e.2 as usize] = dd + e.0;
                pq.push((d[e.2 as usize], e.2 as usize));
            }
        }
    }
    if d[(N-1) as usize] == std::i64::MAX {
        println!("-1");
    } else {
        println!("{}", i64::max(-d[(N-1) as usize], 0));
    }
}


Compiler output:
a.cc:3:2: error: invalid preprocessing directive #[
    3 | #[allow(dead_code)]
      |  ^
a.cc:10:2: error: invalid preprocessing directive #[
   10 | #[allow(dead_code)]
      |  ^
a.cc:18:2: error: invalid preprocessing directive #[
   18 | #[derive(Copy, Clone, Debug)]
      |  ^
a.cc:37:14: error: too many decimal points in number
   37 |     for i in 0..N {
      |              ^~~~
a.cc:43:14: error: too many decimal points in number
   43 |     for i in 0..N {
      |              ^~~~
a.cc:53:14: error: too many decimal points in number
   53 |     for i in 0..N {
      |              ^~~~
a.cc:58:5: warning: missing terminating ' character
   58 |     'outer:
      |     ^
a.cc:58:5: error: missing terminating ' character
   58 |     'outer:
      |     ^~~~~~~
a.cc:70:27: warning: missing terminating ' character
   70 |                     break 'outer;
      |                           ^
a.cc:70:27: error: missing terminating ' character
   70 |                     break 'outer;
      |                           ^~~~~~~
a.cc:1:1: error: 'use' does not name a type
    1 | use std::collections::*;
      | ^~~
a.cc:4:1: error: 'fn' does not name a type
    4 | fn read<T: std::str::FromStr>() -> T {
      | ^~
a.cc:11:1: error: 'fn' does not name a type
   11 | fn read_vec<T: std::str::FromStr>() -> Vec<T> {
      | ^~
a.cc:19:16: error: expected ')' before ',' token
   19 | struct edge(i64, i64, i64);
      |            ~   ^
      |                )
a.cc:19:18: error: aggregate 'edge i64' has incomplete type and cannot be defined
   19 | struct edge(i64, i64, i64);
      |                  ^~~
a.cc:19:26: error: expected initializer before ')' token
   19 | struct edge(i64, i64, i64);
      |                          ^
a.cc:21:1: error: 'fn' does not name a type
   21 | fn dfs(v : i32, g : &Vec<Vec<edge>>, ok : &mut Vec<i32>) {
      | ^~
a.cc:30:1: error: 'fn' does not name a type
   30 | fn main() {
      | ^~