#![allow(unused_imports)] //use itertools::{iproduct, Itertools}; //use proconio::input; //use proconio::marker::*; use std::collections::*; fn main() { input! { n:usize, m:usize, a:[i64;n], uvw:[(usize1,usize1,i64);m], } let mut g = vec![vec![]; n]; for &(u, v, _) in uvw.iter() { g[v].push(u); } let mut vis = vec![false; n]; dfs(n - 1, &mut vis, &g); let uvw = uvw .into_iter() .filter_map(|(u, v, w)| { if u != n - 1 { Some((u, v, -a[u] + w)) } else { None } }) .collect::>(); const INF: i64 = std::i64::MAX; let mut dists = vec![INF; n]; dists[0] = 0; let mut rep = 0; while rep < n { let mut end = true; for &(u, v, w) in uvw.iter() { if vis[v] && dists[u] != INF && dists[u] + w < dists[v] { dists[v] = dists[u] + w; end = false; } } if end { break; } rep += 1; } if rep == n { println!("inf"); } else { let ans = -dists[n - 1] + a[n - 1]; println!("{}", ans); } } fn dfs(crr: usize, vis: &mut Vec, g: &Vec>) { vis[crr] = true; for &nxt in g[crr].iter() { if vis[nxt] { continue; } dfs(nxt, vis, g); } } use input::*; mod input { #[macro_export] macro_rules! input { (source = $s:expr, $($r:tt)*) => { let mut iter = $s.split_whitespace(); input_inner!{iter, $($r)*} }; ($($r:tt)*) => { let s = { use std::io::Read; let mut s = String::new(); std::io::stdin().read_to_string(&mut s).unwrap(); s }; let mut iter = s.split_whitespace(); input_inner!{iter, $($r)*} }; } #[macro_export] macro_rules! input_inner { ($iter:expr) => {}; ($iter:expr, ) => {}; ($iter:expr, $var:ident : $t:tt $($r:tt)*) => { let $var = read_value!($iter, $t); input_inner!{$iter $($r)*} }; } #[macro_export] macro_rules! read_value { ($iter:expr, ( $($t:tt),* )) => { ( $(read_value!($iter, $t)),* ) }; ($iter:expr, [ $t:tt ; $len:expr ]) => { (0..$len).map(|_| read_value!($iter, $t)).collect::>() }; ($iter:expr, chars) => { read_value!($iter, String).chars().collect::>() }; ($iter:expr, usize1) => { read_value!($iter, usize) - 1 }; ($iter:expr, $t:ty) => { $iter.next().unwrap().parse::<$t>().expect("Parse error") }; } }