Language: C++

#[allow(dead_code)]
fn getline() -> String {
    let mut res = String::new();
    std::io::stdin().read_line(&mut res).ok();
    res
}

#[allow(unused_macros)]
macro_rules! readl {
    ($t: ty) => {
        {
            let s = getline();
            s.trim().parse::<$t>().unwrap()
        }
    };
    ($( $t: ty),+ ) => {
        {
            let s = getline();
            let mut iter = s.trim().split(' ');
            ($(iter.next().unwrap().parse::<$t>().unwrap(),)*)
        }
    };
}

#[allow(unused_macros)]
macro_rules! readlvec {
    ($t: ty) => {
        {
            let s = getline();
            let iter = s.trim().split(' ');
            iter.map(|x| x.parse().unwrap()).collect::<Vec<$t>>()
        }
    }
}

#[allow(unused_macros)]
macro_rules! debug { ($x: expr) => { println!("{}: {:?}", stringify!($x), $x) } }
// macro_rules! debug { ($x: expr) => () }

#[allow(dead_code)]
fn show<T>(iter: T) -> String
where
    T: Iterator,
    T::Item: std::fmt::Display
{
    let mut res = iter.fold(String::new(), |sum, e| sum + &format!("{} ", e));
    res.pop();
    res
}

#[allow(unused_imports)]
use std::cmp::{max, min};
#[allow(unused_imports)]
use std::collections::{BTreeMap, BinaryHeap, HashMap, HashSet};
#[allow(unused_imports)]
use std::collections::btree_map::Entry::{Occupied, Vacant};

use std::cmp::Ordering;
use std::clone::Clone;
#[derive(Clone, Debug, Hash, Eq, PartialEq)]
struct Edge<Cost>
where
    Cost: std::clone::Clone,
{
    to: usize,
    cost: Cost,
}

impl<Cost> Ord for Edge<Cost>
where
    Cost: Ord + std::clone::Clone,
{
    fn cmp(&self, other: &Edge<Cost>) -> Ordering {
        (self.cost).cmp(&(other.cost)).reverse()
    }
}

impl<Cost> PartialOrd for Edge<Cost>
where
    Cost: std::clone::Clone,
    Edge<Cost>: Ord,
{
    fn partial_cmp(&self, other: &Edge<Cost>) -> Option<std::cmp::Ordering> {
        Some(self.cmp(other))
    }
}

trait Graph
where
    Self::Cost: Clone
{
    type Cost;
    fn len(&self) -> usize;
    fn get<'a>(&'a self, p: usize) -> std::slice::Iter<'a, Edge<Self::Cost>>;
    fn get_order(&self) -> Vec<usize>;
}

#[derive(Clone, Debug, Hash)]
struct AdjList<Cost: Clone> {
    adj: Vec<Vec<Edge<Cost>>>,
}

impl<Cost: Clone> std::ops::Index<usize> for AdjList<Cost> {
    type Output = Vec<Edge<Cost>>;

    fn index(&self, i: usize) -> &Vec<Edge<Cost>> {
        &self.adj[i]
    }
}

impl<Cost: Clone> std::ops::IndexMut<usize> for AdjList<Cost> {
    fn index_mut<'a>(&'a mut self, i: usize) -> &'a mut Vec<Edge<Cost>> {
        &mut self.adj[i]
    }
}

impl<Cost: Clone> AdjList<Cost> {
    fn new(n: usize) -> AdjList<Cost> {
        AdjList {
            adj: vec![vec![]; n],
        }
    }

    fn add_edge(&mut self, from: usize, to_: usize, cost_: Cost) {
        self.adj[from].push(Edge {
            to: to_,
            cost: cost_,
        });
    }

    fn add_uedge(&mut self, from: usize, to_: usize, cost_: Cost) {
        self.add_edge(from, to_, cost_.clone());
        self.add_edge(to_, from, cost_);
    }
}

impl<Cost> Graph for AdjList<Cost>
where
    Cost: Clone
{
    type Cost = Cost;

    fn len(&self) -> usize {
        self.adj.len()
    }

    fn get<'a>(&'a self, p: usize) -> std::slice::Iter<'a, Edge<Cost>> {
        self.adj[p].iter()
    }

    fn get_order(&self) -> Vec<usize> {
        let mut res = Vec::with_capacity(self.len());
        let mut deg = vec![0; self.len()];
        let mut used = vec![false; self.len()];
        for from in 0..self.len() {
            for e in self.get(from) {
                deg[e.to] += 1;
            }
        }
        for s in 0..self.len() {
            if deg[s] != 0 || used[s] {
                continue;
            }
            let mut stack = Vec::new();
            used[s] = true;
            stack.push(s);
            while let Some(p) = stack.pop() {
                used[p] = true;
                res.push(p);
                for e in self.get(p) {
                    deg[e.to] -= 1;
                    if deg[e.to] == 0 {
                        stack.push(e.to);
                    }
                }
            }

        }
        // debug!(deg);
        res
    }
}

trait Zero {
    fn zero() -> Self;
}

impl Zero for i64 {
    fn zero() -> i64 {
        0
    }
}

trait Max {
    fn max_value() -> Self;
}

impl Max for i64 {
    fn max_value() -> i64 {
        std::i64::MAX
    }
}

trait GraphHavingOrderedCost: Graph
where
    Self::Cost: Ord + Add<Self::Cost, Output = Self::Cost> + Zero + Max + Copy,
{
    fn get_shortest_path(&self, from: usize) -> (Vec<Self::Cost>, Vec<usize>);
    fn bellmanford(&self, from: usize) -> Option<Vec<Self::Cost>>;
    fn get_shortest_path_graph(&self, from: usize, dist: &Vec<Self::Cost>) -> AdjList<Self::Cost>;
}

use std::ops::Add;
impl<T> GraphHavingOrderedCost for T
where
    T: Graph,
    T::Cost: Ord + Add<T::Cost, Output = T::Cost> + Zero + Max + Copy,
    Edge<T::Cost>: Ord,
{
    fn get_shortest_path(&self, from: usize) -> (Vec<Self::Cost>, Vec<usize>) {
        let n = self.len();

        let mut dist = vec![Self::Cost::max_value(); n];
        let mut pre = vec![n as usize; n];
        let mut heap = std::collections::BinaryHeap::new();
        heap.push(Edge {
            to: from,
            cost: Self::Cost::zero(),
        });
        dist[from] = Self::Cost::zero();
        while let Some(p) = heap.pop() {
            for e in self.get(p.to) {
                if p.cost + e.cost >= dist[e.to] {
                    continue;
                }
                heap.push(Edge {
                    to: e.to,
                    cost: p.cost + e.cost,
                });
                dist[e.to] = p.cost + e.cost;
                pre[e.to] = p.to;
            }
        }
        (dist, pre)
    }

    fn bellmanford(&self, from: usize) -> Option<Vec<Self::Cost>> {
        let n = self.len();
        let mut dist = vec![Self::Cost::max_value(); n];
        let mut updated = true;
        dist[from] = Self::Cost::zero();
        for _ in 0..n+1 {
            updated = false;
            for from in 0..n {
                if dist[from] == Self::Cost::max_value() {
                    continue;
                }
                for e in self.get(from) {
                    if dist[e.to] > dist[from]+e.cost {
                        dist[e.to] = dist[from]+e.cost;
                        updated = true;
                    }
                }
            }
        }
        if updated {
            None
        } else {
            Some(dist)
        }
    }

    fn get_shortest_path_graph(&self, from: usize, dist: &Vec<Self::Cost>) -> AdjList<Self::Cost> {
        let n = self.len();

        let mut res = AdjList::new(n);
        for from in 0..n {
            for e in self.get(from) {
                if dist[from] + e.cost == dist[e.to] {
                    res.add_edge(from, e.to, e.cost);
                }
            }
        }
        res
    }
}


use std::io::prelude::*;
impl<Cost: Clone> AdjList<Cost> {
    fn vizualize(&self, name: &str) {
        let path = std::path::Path::new("tmp.dot");
        {
            let mut file = std::fs::File::create(path).unwrap();
            let n = self.len();
            file.write_all("digraph graph_name {\n".as_bytes()).unwrap();
            for p in 0..n {
                let s = ["    ".to_string(), p.to_string(), "[];\n".to_string()].connect("");
                file.write_all(s.as_bytes()).unwrap();
            }
            for p in 0..n {
                for e in &self[p] {
                    file.write_all(b"    ").unwrap();
                    file.write_all(p.to_string().as_bytes()).unwrap();
                    file.write_all(b" -> ").unwrap();
                    file.write_all(e.to.to_string().as_bytes()).unwrap();
                    file.write_all(b"\n").unwrap();
                }
            }
            file.write(b"}\n").unwrap();
        }
        let mut cmd = std::process::Command::new("dot");
        cmd.arg("-T");
        cmd.arg("png");
        cmd.arg("tmp.dot");
        cmd.arg("-o");
        cmd.arg(name);
        cmd.status().expect("commend failed to start");
    }
}

fn main() {
    use std::io::Write;
    let out = std::io::stdout();
    let mut out = std::io::BufWriter::new(out.lock());
    macro_rules! printf { ($($arg:tt)*) => (write!(out, $($arg)*).unwrap()); }
    macro_rules! printfln { () => (writeln!(out).unwrap()); ($($arg:tt)*) => (writeln!(out, $($arg)*).unwrap()); }
    
    let (n, m) = readl!(usize, usize);
    let mut g = AdjList::new(n);
    for _ in 0..m {
        let (a, b, c) = readl!(usize, usize, i64);
        g.add_edge(a-1, b-1, -c);
    }
    if let Some(v) = g.bellmanford(0) {
        printfln!("{}", -v[n-1]);
    } else {
        printfln!("inf");
    }
}


Compiler output:
a.cc:1:2: error: invalid preprocessing directive #[
    1 | #[allow(dead_code)]
      |  ^
a.cc:8:2: error: invalid preprocessing directive #[
    8 | #[allow(unused_macros)]
      |  ^
a.cc:25:2: error: invalid preprocessing directive #[
   25 | #[allow(unused_macros)]
      |  ^
a.cc:36:2: error: invalid preprocessing directive #[
   36 | #[allow(unused_macros)]
      |  ^
a.cc:40:2: error: invalid preprocessing directive #[
   40 | #[allow(dead_code)]
      |  ^
a.cc:51:2: error: invalid preprocessing directive #[
   51 | #[allow(unused_imports)]
      |  ^
a.cc:53:2: error: invalid preprocessing directive #[
   53 | #[allow(unused_imports)]
      |  ^
a.cc:55:2: error: invalid preprocessing directive #[
   55 | #[allow(unused_imports)]
      |  ^
a.cc:60:2: error: invalid preprocessing directive #[
   60 | #[derive(Clone, Debug, Hash, Eq, PartialEq)]
      |  ^
a.cc:94:12: warning: multi-character character constant [-Wmultichar]
   94 |     fn get<'a>(&'a self, p: usize) -> std::slice::Iter<'a, Edge<Self::Cost>>;
      |            ^~~~~~~
a.cc:94:56: warning: missing terminating ' character
   94 |     fn get<'a>(&'a self, p: usize) -> std::slice::Iter<'a, Edge<Self::Cost>>;
      |                                                        ^
a.cc:94:56: error: missing terminating ' character
   94 |     fn get<'a>(&'a self, p: usize) -> std::slice::Iter<'a, Edge<Self::Cost>>;
      |                                                        ^~~~~~~~~~~~~~~~~~~~~~
a.cc:98:2: error: invalid preprocessing directive #[
   98 | #[derive(Clone, Debug, Hash)]
      |  ^
a.cc:112:18: warning: multi-character character constant [-Wmultichar]
  112 |     fn index_mut<'a>(&'a mut self, i: usize) -> &'a mut Vec<Edge<Cost>> {
      |                  ^~~~~~~
a.cc:112:50: warning: missing terminating ' character
  112 |     fn index_mut<'a>(&'a mut self, i: usize) -> &'a mut Vec<Edge<Cost>> {
      |                                                  ^
a.cc:112:50: error: missing terminating ' character
  112 |     fn index_mut<'a>(&'a mut self, i: usize) -> &'a mut Vec<Edge<Cost>> {
      |                                                  ^~~~~~~~~~~~~~~~~~~~~~~~
a.cc:147:12: warning: multi-character character constant [-Wmultichar]
  147 |     fn get<'a>(&'a self, p: usize) -> std::slice::Iter<'a, Edge<Cost>> {
      |            ^~~~~~~
a.cc:147:56: warning: missing terminating ' character
  147 |     fn get<'a>(&'a self, p: usize) -> std::slice::Iter<'a, Edge<Cost>> {
      |                                                        ^
a.cc:147:56: error: missing terminating ' character
  147 |     fn get<'a>(&'a self, p: usize) -> std::slice::Iter<'a, Edge<Cost>> {
      |                                                        ^~~~~~~~~~~~~~~~~
a.cc:155:21: error: too many decimal points in number
  155 |         for from in 0..self.len() {
      |                     ^~~~~~~~~~~
a.cc:160:18: error: too many decimal points in number
  160 |         for s in 0..self.len() {
      |                  ^~~~~~~~~~~
a.cc:252:18: error: too many decimal points in number
  252 |         for _ in 0..n+1 {
      |                  ^~~~
a.cc:254:25: error: too many decimal points in number
  254 |             for from in 0..n {
      |                         ^~~~
a.cc:277:21: error: too many decimal points in number
  277 |         for from in 0..n {
      |                     ^~~~
a.cc:297:22: error: too many decimal points in number
  297 |             for p in 0..n {
      |                      ^~~~
a.cc:301:22: error: too many decimal points in number
  301 |             for p in 0..n {
      |                      ^~~~
a.cc:331:14: error: too many decimal points in number
  331 |     for _ in 0..m {
      |              ^~~~
a.cc:2:1: error: 'fn' does not name a type
    2 | fn getline() -> String {
      | ^~
a.cc:9:1: error: 'macro_rules' does not name a type
    9 | macro_rules! readl {
      | ^~~~~~~~~~~
a.cc:26:1: error: 'macro_rules' does not name a type
   26 | macro_rules! readlvec {
      | ^~~~~~~~~~~
a.cc:37:1: error: 'macro_rules' does not name a type
   37 | macro_rules! debug { ($x: expr) => { println!("{}: {:?}", stringify!($x), $x) } }
      | ^~~~~~~~~~~
a.cc:41:1: error: 'fn' does not name a type
   41 | fn show<T>(iter: T) -> String
      | ^~
a.cc:52:1: error: 'use' does not name a type
   52 | use std::cmp::{max, min};
      | ^~~
a.cc:54:1: error: 'use' does not name a type
   54 | use std::collections::{BTreeMap, BinaryHeap, HashMap, HashSet};
      | ^~~
a.cc:56:1: error: 'use' does not name a type
   56 | use std::collections::btree_map::Entry::{Occupied, Vacant};
      | ^~~
a.cc:58:1: error: 'use' does not name a type
   58 | use std::cmp::Ordering;
      | ^~~
a.cc:59:1: error: 'use' does not name a type
   59 | use std::clone::Clone;
      | ^~~
a.cc:61:8: error: 'Edge' is not a class template
   61 | struct Edge<Cost>
      |        ^~~~
a.cc:61:13: error: 'Cost' was not declared in this scope
   61 | struct Edge<Cost>
      |             ^~~~
a.cc:63:5: error: expected initializer before 'Cost'
   63 |     Cost: std::clone::Clone,
      |     ^~~~
a.cc:69:1: error: 'impl' does not name a type
   69 | impl<Cost> Ord for Edge<Cost>
      | ^~~~
a.cc:78:1: error: 'impl' does not name a type
   78 | impl<Cost> PartialOrd for Edge<Cost>
      | ^~~~
a.cc:88:1: error: 'trait' does not name a type
   88 | trait Graph
      | ^~~~~
a.cc:99:8: error: 'AdjList' is not a class template
   99 | struct AdjList<Cost: Clone> {
      |        ^~~~~~~
a.cc:99:16: error: 'Cost' was not declared in this scope
   99 | struct AdjList<Cost: Clone> {
      |                ^~~~
a.cc:100:5: error: 'adj' does not name a type
  100 |     adj: Vec<Vec<Edge<Cost>>>,
      |     ^~~
a.cc:103:5: error: expected initializer before '<' token
  103 | impl<Cost: Clone> std::ops::Index<usize> for AdjList<Cost> {
      |     ^
a.cc:111:1: error: 'impl' does not name a type
  111 | impl<Cost: Clone> std::ops::IndexMut<usize> for AdjList<Cost> {
      | ^~~~
a.cc:115:1: error: expected declaration before '}' token
  115 | }
      | ^
a.cc:117:1: error: 'impl' does not name a type
  117 | impl<Cost: Clone> AdjList<Cost> {
      | ^~~~
a.cc:137:1: error: 'impl' does not name a type
  137 | impl<Cost> Graph for AdjList<Cost>
      | ^~~~
a.cc:151:5: error: 'fn' does not name a type
  151 |     fn get_order(&self) -> Vec<usize> {
      |     ^~
a.cc:182:1: error: expected declaration before '}' token
  182 | }
      | ^
a.cc:184:1: error: 'trait' does not name a type
  184 | trait Zero {
      | ^~~~~
a.cc:188:1: error: 'impl' does not name a type
  188 | impl Zero for i64 {
      | ^~~~
a.cc:194:1: error: 'trait' does not name a type
  194 | trait Max {
      | ^~~~~
a.cc:198:1: error: 'impl' does not name a type
  198 | impl Max for i64 {
      | ^~~~
a.cc:204:1: error: 'trait' does not name a type
  204 | trait GraphHavingOrderedCost: Graph
      | ^~~~~
a.cc:213:1: error: 'use' does not name a type
  213 | use std::ops::Add;
      | ^~~
a.cc:214:1: error: 'impl' does not name a type
  214 | impl<T> GraphHavingOrderedCost for T
      | ^~~~
a.cc:289:1: error: 'use' does not name a type
  289 | use std::io::prelude::*;
      | ^~~
a.cc:290:1: error: 'impl' does not name a type
  290 | impl<Cost: Clone> AdjList<Cost> {
      | ^~~~
a.cc:322:1: error: 'fn' does not name a type
  322 | fn main() {
      | ^~