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
#include <cstdio>
#include <map>
#include <utility>
#include <vector>
using namespace std;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define VAR(v,w) __typeof(w) v=(w)
#define FORE(it,c) for(VAR(it,(c).begin());it!=(c).end();++it)
#define PB push_back
#define MP make_pair
#define INT(x) int x; scanf("%d", &x)
#define LLG(x) LL x; scanf("%lld", &x)

typedef long long LL;
typedef pair<int,int> PII;
typedef vector<int> VI;

LL z[100000];
VI g[100000];
int e[200000];
LL c[200000];
int ee;
map<PII, int> idx;
int now;
LL best;
int nxt;

void go(int ee, LL s) {
	int i = e[ee], p = e[ee ^ 1];
	s += c[ee];
	LL here = z[i] - s;
	if (nxt < 0 || here > best) {
		nxt = i;
		best = here;
	} else if (nxt >= 0 && here == best)
		nxt = min(nxt, i);
	FORE(it,g[i]) if (e[*it] != p) go(*it, s);
}

int main() {
	INT(n);
	INT(q);
	REP(i,n) scanf("%lld", &z[i]);
	REP(i,n-1) {
		INT(a);
		INT(b);
		LLG(cc);
		--a;
		--b;
		e[ee] = b;
		c[ee] = cc;
		g[a].PB(ee);
		idx[MP(a, b)] = ee;
		++ee;
		e[ee] = a;
		c[ee] = cc;
		g[b].PB(ee);
		idx[MP(b, a)] = ee;
		++ee;
	}
	REP(i,q) {
		INT(op);
		if (op == 1) {
			INT(v);
			LLG(d);
			z[v - 1] = d;
		} else {
			INT(a);
			INT(b);
			LLG(cc);
			int id = idx[MP(a - 1, b - 1)];
			c[id] = c[id ^ 1] = cc;
		}
		best = -8000000000000000000LL;
		nxt = -1;
		FORE(it,g[now]) go(*it, 0);
		if (i) printf(" ");
		printf("%d", nxt + 1);
		now = nxt;
	}
	printf("\n");
}