1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
#include <bits/stdc++.h>
#define MP make_pair
#define PB push_back
#define int long long
#define st first
#define nd second
#define rd third
#define FOR(i, a, b) for(int i =(a); i <=(b); ++i)
#define RE(i, n) FOR(i, 1, n)
#define FORD(i, a, b) for(int i = (a); i >= (b); --i)
#define REP(i, n) for(int i = 0;i <(n); ++i)
#define VAR(v, i) __typeof(i) v=(i)
#define FORE(i, c) for(VAR(i, (c).begin()); i != (c).end(); ++i)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
using namespace std;
template<typename TH> void _dbg(const char* sdbg, TH h) { cerr<<sdbg<<"="<<h<<"\n"; }
template<typename TH, typename... TA> void _dbg(const char* sdbg, TH h, TA... t) {
  while(*sdbg != ',')cerr<<*sdbg++; cerr<<"="<<h<<","; _dbg(sdbg+1, t...);
}
#ifdef LOCAL
#define debug(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#define debugv(x) {{cerr <<#x <<" = "; FORE(itt, (x)) cerr <<*itt <<", "; cerr <<"\n"; }}
#else
#define debug(...) (__VA_ARGS__)
#define debugv(x)
#define cerr if(0)cout
#endif
#define left ____left
#define hash ____hash
typedef long long ll;
typedef long double LD;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VLL;
typedef vector<pair<int, int> > VPII;
typedef vector<pair<ll, ll> > VPLL;

template<class C> void mini(C&a4, C b4){a4=min(a4, b4); }
template<class C> void maxi(C&a4, C b4){a4=max(a4, b4); }
template<class T1, class T2>
ostream& operator<< (ostream &out, pair<T1, T2> pair) { return out << "(" << pair.first << ", " << pair.second << ")";}
template<class A, class B, class C> struct Triple { A first; B second; C third;
  bool operator<(const Triple& t) const { if (st != t.st) return st < t.st; if (nd != t.nd) return nd < t.nd; return rd < t.rd; } };
template<class T> void ResizeVec(T&, vector<int>) {}
template<class T> void ResizeVec(vector<T>& vec, vector<int> sz) {
  vec.resize(sz[0]); sz.erase(sz.begin()); if (sz.empty()) { return; }
  for (T& v : vec) { ResizeVec(v, sz); }
}
typedef Triple<int, int, int> TIII;
template<class A, class B, class C>
ostream& operator<< (ostream &out, Triple<A, B, C> t) { return out << "(" << t.st << ", " << t.nd << ", " << t.rd << ")"; }
template<class T> ostream& operator<<(ostream& out, vector<T> vec) { out<<"("; for (auto& v: vec) out<<v<<", "; return out<<")"; }

const int N = 1e5 + 5;
int prof[N];
int sum_ends[N];
int costs[N];
int n, q;

struct Node {
  int m, to_push, wh;
};
const int kInf = 3e18;
struct Tree {
  vector<Node> nodes;
  int M;
  int init;
  int base;
  Tree(int b) {
    base = b;
    M = 1;
    init = 0;
    while (M <= base) {
      M = 2 * M;
    }
    nodes.resize(2 * M);
    FOR (i, base + 1, M) {
      nodes[M - 1 + i].m = -kInf;
    }
  }
  void FillWh(int i, int v) {
    debug(i, base, v);
    nodes[M - 1 + i].wh = v;
  }
  void UpdMax(int ind) {
    if (nodes[2 * ind].m > nodes[2 * ind + 1].m ||
        (nodes[2 * ind].m == nodes[2 * ind + 1].m && nodes[2 * ind].wh < nodes[2 * ind + 1].wh)) {
      nodes[ind].m = nodes[2 * ind].m;
      nodes[ind].wh = nodes[2 * ind].wh;
    } else {
      nodes[ind].m = nodes[2 * ind + 1].m;
      nodes[ind].wh = nodes[2 * ind + 1].wh;
    }
  }
  void UpdAllMax() {
    init = 1;
    debug(base);
    RE (i, base) {
      assert(nodes[M - 1 + i].wh);
    }
    FORD (i, M - 1, 1) {
      UpdMax(i);
    }
  }
  void Add(int a, int b, int val) {
    assert(init);
    AddRec(a, b, 1, M, 1, val);
  }
  void Touch(int v) {
    assert(v < M);
    FOR (ch, 2 * v, 2 * v + 1) {
      nodes[ch].m += nodes[v].to_push;
      nodes[ch].to_push += nodes[v].to_push;
    }
    nodes[v].to_push = 0;
  }
  void AddRec(int a, int b, int bl, int br, int ind, int val) {
    if (b < bl || a > br) { return; }
    if (a <= bl && br <= b) {
      nodes[ind].m += val;
      nodes[ind].to_push += val;
      return;
    }
    int m = (bl + br) / 2;
    Touch(ind);
    AddRec(a, b, bl, m, 2 * ind, val);
    AddRec(a, b, m + 1, br, 2 * ind + 1, val);
    UpdMax(ind);
  }
  int Read(int pt) {
    assert(init);
    return ReadRec(pt, 1, M, 1);
  }
  int ReadRec(int pt, int bl, int br, int ind) {
    if (bl == br) {
      return nodes[ind].m;
    }
    int m = (bl + br) / 2;
    Touch(ind);
    if (pt <= m) {
      return ReadRec(pt, bl, m, 2 * ind);
    } else {
      return ReadRec(pt, m + 1, br, 2 * ind + 1);
    }
  }
};

struct Res {
  int res, v, subtr;
  bool operator<(const Res& oth) const {
    if (res != oth.res) {
      return res > oth.res;
    }
    if (v != oth.v) {
      return v < oth.v;
    }
    return subtr < oth.subtr;
  }
  friend ostream& operator<<(ostream& out, Res p);
};

ostream& operator<<(ostream& out, Res r) {
  out << "(" << r.res << ", " << r.v << ", " << r.subtr << ")";
  return out;
}

struct CentDecomp {
  
  /* Start of general part */
  VVI slo;
  int n;
  VI sz;
  struct Info {
    int cent, subtr;
    PII pre_intv;
  };
  
      
  vector<vector<Info>> cents_v;
  vector<vector<Info>> cents_e;
  vector<set<Res>> cands;
  vector<vector<Tree>> trees_prof;
  vector<vector<Res>> branch_res;
  vector<int> wei_v;
  vector<int> wei_e;
  CentDecomp(VVI& slo_, int n_) {
    slo = slo_;
    n = n_;
    cands.resize(n + 2);
    branch_res.resize(n + 2);
    trees_prof.resize(n + 2);
    sz.resize(n + 2);
    cents_v.resize(n + 2);
    cents_e.resize(n + 2);
    wei_v.resize(n + 2);
    wei_e.resize(n + 2);
    Rec(1, n);
  }
  
  int d;
  void Rec(int v, int size) {
    debug(v, size, "bef");
    d = 0;
    int orig_v = v;
    vector<int> my_preorder;
    v = CntSzCent(v, size, -1, 0, 0, -1, my_preorder, 0);
    debug(v, orig_v);
    d = 0;
    my_preorder = {-1};
    CntSzCent(v, size, -1, v, SZ(slo[v]), -1, my_preorder, 0);
    debug(my_preorder, sz[v], slo[v]);
    int eaten = 1;
    for (int i = 0; i < SZ(slo[v]); i++) {
      int nei = sum_ends[slo[v][i]] - v;
      trees_prof[v].PB(Tree(sz[nei]));
      RE (j, sz[nei]) {
        debug(SZ(my_preorder), j, eaten, i, nei);
        trees_prof[v].back().FillWh(j, my_preorder[eaten + j]);
      }
      trees_prof[v].back().UpdAllMax();
      branch_res[v].PB({-kInf, -1, -1});
      eaten += sz[nei];
      DelEdge(nei, slo[v][i]);
      Rec(nei, sz[nei]);
    }
    trees_prof[v].PB(Tree(1));
    trees_prof[v].back().FillWh(1, v);
    trees_prof[v].back().UpdAllMax();
    branch_res[v].PB({-kInf, -1, 1});
  }

  int CntSzCent(int v, int size, int par, int root, int subtr, int par_e, vector<int>& pre, int to_sub_pre) {
    assert(v >= 1);
    d++;
    sz[v] = 1;
    int my_pre = d;
    int my_subtr = subtr;
    int cp_to_sub_pre = to_sub_pre;
    int ret = 0;
    if (root) {
      pre.PB(v);
    }
    for (int i = 0; i < SZ(slo[v]); i++) {
      int nei = sum_ends[slo[v][i]] - v;
      if (v == root) {
        subtr = i;
        to_sub_pre = d;
      }
      if (par == nei) { continue; }
      int cnt_rec = CntSzCent(nei, size, v, root, subtr, slo[v][i], pre, to_sub_pre);
      sz[v] += sz[nei];
      if (cnt_rec) {
        ret = cnt_rec;
      }
    }
    if (root) {
      cents_v[v].PB({root, my_subtr, {my_pre - cp_to_sub_pre, my_pre - cp_to_sub_pre}});
      if (par_e != -1) {
        cents_e[par_e].PB({root, my_subtr, {my_pre - cp_to_sub_pre, my_pre + sz[v] - 1 - cp_to_sub_pre}});
      }
    }
    if (ret == 0) {
      if (sz[v] >= size / 2) {
        return v;
      } else {
        return 0;
      }
    } else {
      return ret;
    }
  }
  
  void DelEdge(int v, int e) {
    for (int i = 0; i < SZ(slo[v]); i++) {
      if (slo[v][i] == e) {
        swap(slo[v][i], slo[v].back());
        slo[v].pop_back();
        return;
      }
    }
    assert(false);
  }
  /* End of general part */
  
  /* Start of less general part */
  void FixCands(Info& info, int to_add) {
    auto& secik = cands[info.cent];
    secik.erase(branch_res[info.cent][info.subtr]);
    auto& T = trees_prof[info.cent][info.subtr];
    debug(info.cent, info.subtr, to_add, info.pre_intv);
    T.Add(info.pre_intv.st, info.pre_intv.nd, to_add);
    branch_res[info.cent][info.subtr] = {T.nodes[1].m, T.nodes[1].wh, info.subtr};
    debug(branch_res[info.cent][info.subtr]);
    secik.insert(branch_res[info.cent][info.subtr]);
  }
  void ChangeV(int v, int new_val) {
    int diff = new_val - wei_v[v];
    wei_v[v] = new_val;
    for (auto& info : cents_v[v]) {
      FixCands(info, diff);
    }
  }
  void ChangeE(int e, int new_val) {
    int diff = new_val - wei_e[e];
    wei_e[e] = new_val;
    for (auto& info : cents_e[e]) {
      FixCands(info, -diff);
    }
  }
  
  PII Query(int v) {
    debug("Query", v);
    PII res = {-kInf, -1};
    for (auto& info : cents_v[v]) {
      auto& secik = cands[info.cent];
      if (secik.empty()) { continue; }
      Res fir_cand = *(secik.begin());
      Res best_here{-kInf, -1, -1};
      if (fir_cand.subtr != info.subtr) {
        best_here = fir_cand;
      } else if (SZ(secik) > 1) {
        best_here = *(next(secik.begin()));
      }
      int dis = wei_v[v] - trees_prof[info.cent][info.subtr].Read(info.pre_intv.st);
      debug(v, info.cent, dis, info.pre_intv);
      PII cand = {best_here.res - dis, best_here.v};
      if (res.st < cand.st || (res.st == cand.st && cand.nd < res.nd)) {
        res = cand;
      }
    }
    return res;
  }
  /* End of less general part */
};

    
int32_t main() {

  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(10);
  cerr << fixed << setprecision(10);
  cin.tie(0);
  //double beg_clock = 1.0 * clock() / CLOCKS_PER_SEC;
  
  cin>>n>>q;
  RE (i, n) {
    cin>>prof[i];
  }
  map<PII, int> mapuj;
  VVI slo(n + 1);
  RE (i, n - 1) {
    int a, b;
    cin>>a>>b>>costs[i];
    slo[a].PB(i);
    slo[b].PB(i);
    sum_ends[i] = a + b;
    mapuj[{a, b}] = i;
    mapuj[{b, a}] = i;
  }
  CentDecomp decomp(slo, n);
  RE (i, n) {
    cerr<<"infos "<<i<<endl;
    for (auto info : decomp.cents_v[i]) {
      cerr<<info.cent<<" "<<info.subtr<<" "<<info.pre_intv<<endl;
    }
  }
  RE (i, n - 1) {
    cerr<<"infose "<<i<<endl;
    for (auto info : decomp.cents_e[i]) {
      cerr<<info.cent<<" "<<info.subtr<<" "<<info.pre_intv<<endl;
    }
  }
  RE (i, n) {
    decomp.ChangeV(i, prof[i]);
  }
  RE (i, n - 1) {
    decomp.ChangeE(i, costs[i]);
  }
  RE (i, n) {
    debug(decomp.branch_res[i]);
  }
  int cur = 1;
  RE (i, q) {
    int typ;
    cin>>typ;
    if (typ == 1) {
      int v, d;
      cin>>v>>d;
      decomp.ChangeV(v, d);
    } else {
      int a, b, d;
      cin>>a>>b>>d;
      decomp.ChangeE(mapuj[{a, b}], d);
    }
    PII res = decomp.Query(cur);
    debug(res);
    cur = res.nd;
    cout<<cur<<" ";
  }
  cout<<endl;

  return 0;
}