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
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;

typedef long long ll;

const int MAX = 100010;
vector<int> G[MAX];
vector<int> SH[MAX];
ll GD[MAX];

int QE[MAX];
int W[MAX];
ll T[MAX];
ll DS[MAX];


int main()
{
    int n,q;
    scanf("%d%d",&n,&q);
    for(int i=0;i<n;++i) scanf("%lld",&T[i]);
    int a,b;
    ll c;
    int wg=0;
    for(int i=0;i<n-1;++i)
    {
        scanf("%d%d",&a,&b);
        scanf("%lld",&c);
        GD[wg]=c;
        G[a-1].push_back(b-1);
        G[b-1].push_back(a-1);
        SH[a-1].push_back(wg);
        SH[b-1].push_back(wg);
        ++wg;
    }
    int v;
    int r;
    ll d;
    int ac=0;
    for(int j=1;j<=q;++j)
    {
        scanf("%d",&r);
        if (r==1)
        {
            scanf("%d",&v);
            scanf("%lld",&d);
            T[v-1]=d;
        }
        else
        {
            scanf("%d%d",&a,&b);
            scanf("%lld",&d);
            for(int i=0;i<G[a-1].size();++i)
            {
                if (G[a-1][i]==b-1)
                {
                    GD[SH[a-1][i]]=d;
                    break;
                }
            }
        }

        W[ac]=j;
        QE[0]=ac;
        int w1=0,w2=1;
        ll cn=-1000000000000000000L;
        DS[ac]=0L;
        while(w1<w2)
        {
            int cv=QE[w1++];
            for(int i=0;i<G[cv].size();++i)
            {
                int ng=G[cv][i];
                ll ds=GD[SH[cv][i]];
                if (W[ng]==j) continue;
                W[ng]=j;
                QE[w2++]=ng;
                DS[ng]=DS[cv]+ds;
                if (T[ng]-DS[ng]>cn||(T[ng]-DS[ng]==cn&&ng<ac))
                {
                    cn=T[ng]-DS[ng];
                    ac=ng;
                }

            }
        }
        printf("%d ", ac+1);
    }

    return 0;
}