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

#define REP(i, M) for(int i = 0; i < M; i++)
#define R(p, k) for(int i = p; i <= k; i++)
#define RI(j, p, k) for(int j = p; j <= k; j++)
#define PB push_back
#define FI first
#define SE second
#define LL long long 


#define DEB 1

#if DEB
	#define CEN cerr << endl;
	#define CEL(a) cerr << #a << ": " << a << " "; 
	#define CES(s) cerr << s << endl;
#else
	#define CEN 
	#define CEL(a) 
	#define CES(s) 
#endif

const LL INF = (LL)1000 * 1000 * 1000 * 1000 * 1000 * 1000;
const int MN = 100 * 1000 + 5;
int n, q;
LL zysk[MN];
vector<pair<int, LL> > adj[MN];
LL res;
int resv;

void dfs(int v, int oj, LL pref){
    //CEL(v);
    for (auto p : adj[v]){
        int w = p.first;
        //CEL(w);
        if (w == oj)
            continue;
        
        LL nres = zysk[w] - (pref + p.second);
        //CEL(w);
        //CEL(nres);
        if (nres > res || (nres == res && w < resv)){
            res = nres;
            resv = w;
        }
        dfs(w, v, pref + p.second);
    }
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
        int v, w, d;
        LL c;
        cin >> n >> q;
        for(int i = 1; i <= n; i++)
            cin >> zysk[i];
        
        for(int i = 0; i < (n - 1); i++){
            cin >> v >> w >> c;
            adj[v].PB({w, c});
            adj[w].PB({v, c});
        }
        
        int lastv = 1;
        for(int j = 0; j < q; j++){
            cin >> d;
            if (d == 1){
                cin >> v >> c;
                zysk[v] = c;
            }
            else{
                cin >> v >> w >> c;
                for (auto &p : adj[v]){
                    if (p.first == w){
                        p.second = c;
                        break;
                    }
                }
                
                for (auto &p : adj[w]){
                    if (p.first == v){
                        p.second = c;
                        break;
                    }
                }
                
            }
            
            res = -INF;
            resv = MN;
            dfs(lastv, 0, 0);
            lastv = resv;
            cout << lastv << " ";
            
        }
        cout << endl;        
	return 0;
}