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
#include <bits/stdc++.h>
using namespace std;

#ifndef _WIN32
    #define getchar getchar_unlocked
#endif

#define MP make_pair
#define PB push_back
#define ST first
#define ND second

typedef long long int LLI;
typedef unsigned long long int LLU;
typedef long double LD;
typedef pair<int, int> pii;
typedef pair<long long int, long long int> pll;
typedef vector<int> vi;

template<class TH> void _dbg(const char *sdbg, TH h){cerr<<sdbg<<"="<<h<<"\n";}
template<class TH, class... TA> void _dbg(const char *sdbg, TH h, TA... a) {
  while(*sdbg!=',') cerr<<*sdbg++;
  cerr<<"="<<h<<",";
  _dbg(sdbg+1, a...);
}
#define debug(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#define boost ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)

const int MX = 100007;
vector<pair<int, LLI> > G[MX];
LLI cost[MX];

int nr; LLI wyn;
void dfs(int u, int p, LLI w){
	if(p != 0){
		if(wyn < cost[u] - w){
			wyn = cost[u] - w;
			nr = u;
		}
		else if(wyn == cost[u] - w && u < nr){
			nr = u;
		}
	}
	for(auto q : G[u])
		if(q.ST != p)
			dfs(q.ST, u, w + q.ND);
}

int32_t main()
{
	int n, q; scanf("%d%d", &n, &q);
	for(int i = 1; i <= n; ++i) scanf("%lld", &cost[i]);
	for(int i = 1; i < n; ++i){
		int a, b; LLI c; scanf("%d%d%lld", &a, &b, &c);
		G[a].PB({b, c}); G[b].PB({a, c});
	}
	int odp = 1;
	while(q--){
		int t; scanf("%d", &t);
		if(t == 1){
			int v; scanf("%d", &v); scanf("%lld", &cost[v]);
		}
		else{
			int a, b; LLI c; scanf("%d%d%lld", &a, &b, &c);
			for(int i = 0; i < int(G[a].size()); ++i)
				if(G[a][i].ST == b) G[a][i].ND = c;
			for(int i = 0; i < int(G[b].size()); ++i)
				if(G[b][i].ST == a) G[b][i].ND = c;
		}
		wyn = -LLONG_MAX; 
		dfs(odp, 0, 0);
		odp = nr; printf("%d ", nr);
	}
}