#include #ifdef LOCAL #include "./debug.cpp" #else #define debug(...) #define print_line #endif using namespace std; using ll = long long; int main() { int N, M; cin >> N >> M; vector A(N); for (int i = 0; i < N; i++) { cin >> A[i]; } vector>> G(N); for (int i = 0; i < M; i++) { int a, b; ll c; cin >> a >> b >> c; a--; b--; G[a].push_back({b, c}); } // bellman-ford vector dst(N, LLONG_MIN); dst[0] = 0; for (int i = 0; i < N; i++) { bool fin = true; for (int j = 0; j < N; j++) { for (auto [nxt, cost] : G[j]) { if (dst[nxt] < dst[j] + A[j] - cost) { dst[nxt] = dst[j] + A[j] - cost; fin = false; } } } if (fin) { break; } if (i == N - 1) { cout << "inf" << endl; return 0; } } cout << dst[N - 1] + A[N - 1] << endl; }