#include using namespace std; #include using namespace atcoder; using ll = long long; int N,M; vector A; using P = pair; vector> G; vector> nG; void solve(){ nG = vector>(N); for(int i = 0;i dist(N,1e18); dist[0] = -A[0]; for(int t= 0;tdist[i]+cost){ dist[to] = dist[i]+cost; } } } } vector updated(N); ll INF = 1e18; for(int t = 0;tdist[i]+cost){ dist[to] = dist[i]+cost; updated[to] = 1; } } } } for(int t = 0;t < N;t++){ for(int i = 0;i> N >> M; A.resize(N); for(int i = 0; i < N; ++i) cin >> A[i]; G.resize(N); for(int i = 0; i < M; ++i){ ll a,b,c; cin >> a >> b >> c; --a; --b; G[a].push_back({b,c}); } solve(); }