#include using namespace std; #define all(v) (v).begin(),(v).end() #define pb(a) push_back(a) #define rep(i, n) for(int i=0;i std::vector bellman_ford(T &G, int start, int lim = -1){ // T -> vector>> // edge pair -> pair int n = G.size(); std::vector dis(n, (1LL << 59)); dis[start] = 0; lim = 20000; for(int i = 0; i < lim; i ++) {// 2N 回やると検出とか楽 bool update = 0; for(int j = 0; j < n; j ++) { for(auto [cost, to] : G[j]) { if(dis[j] + cost < dis[to]) { dis[to] = dis[j] + cost; if(i >= 7000 and to == n - 1) { if(dis[to] < INF/2LL) { flag = 1; return dis; } } update = 1; } } } if(!update) break; } return dis; } int main() { cin.tie(0); ios::sync_with_stdio(false); ll n, m; cin >> n >> m; vector a(n); rep(i, n) cin >> a[i]; vector>> v(n * 2); rep(i, m) { ll x, y, c; cin >> x >> y >> c; x --; y --; v[x * 2 + 1].push_back({c, y * 2}); } rep(i, n) v[i*2].push_back({-a[i], i*2+1}); auto ret = bellman_ford(v, 0); if(flag) { cout << "inf" << endl; return 0; } // cout << INF << endl; cout << - ret.back() << endl; return 0; }