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
#include <cstdio>
#include <cstring>
#include <vector>
#include <set>

using namespace std;

const int N = 200001;

long long z[N];

vector<pair<int, long long>> E[N];
set<pair<int, int>> S[N];

int visit[N];
long long cost[N];

void dfs(int u)
{
  visit[u] = 1;
  for (int i = 0; i < E[u].size(); i++)
  {
    int v = E[u][i].first;
    int koszt = E[u][i].second;
    if (!visit[v])
    {
      cost[v] = cost[u] + koszt;
      dfs(v);
    }
  }
}

int main()

{
  int n, q;
  scanf("%d %d", &n, &q);
  
  for (int i = 1; i <= n; i++)
  {
    scanf("%lld", z + i);
  }
  
  for (int i = 0; i < n - 1; i++)
  {
    int a, b;
    long long c;
    scanf("%d %d %lld", &a, &b, &c);
    
    E[a].push_back({b, c});
    S[a].insert({b, E[a].size() - 1});
    E[b].push_back({a, c});
    S[b].insert({a, E[b].size() - 1});
  }
  
  int start = 1;
  for (int i = 0; i < q; i++)
  {
    memset(visit, 0, sizeof(visit));
    memset(cost, 0, sizeof(cost));
    int a, b, c;
    long long d;
    scanf("%d", &a);
    if (a == 1)
    {
      scanf("%d %lld", &b, &d);
      z[b] = d;
    }
    else
    {
      scanf("%d %d %lld", &b,&c, &d);
      
      auto it = S[b].lower_bound({c, -1});
      int idx = it->second;
      E[b][idx].second = d;

      it = S[c].lower_bound({b, -1});
      idx = it->second;
      E[c][idx].second = d;
      
      /*for (int j = 0; j < E[b].size(); j++)
      {
        if (E[b][j].first == c)
        {
          E[b][j].second = d;
          break;
        }
      }
      for (int j = 0; j < E[c].size(); j++)
      {
        if (E[c][j].first == b)
        {
          E[c][j].second = d;
          break;
        }
      }*/
    }
    
    dfs(start);
    pair<long long, int> best = {0, 0};
    for (int j = 1; j <= n; j++)
    {
      if (j == start) continue;
      best.first = z[j] - cost[j];
      best.second = j;
      break;
    }

    for (int j = 1; j <= n; j++)
    {
      if (j == start) continue;
      if (z[j] - cost[j] > best.first) 
      {
        best.first = z[j] - cost[j];
        best.second = j;
      }
      else
      {
        if (z[j] - cost[j] == best.first)
        {
          if (j < best.second)
          {
            best.second = j;
          }
        }
      }
    }
    /*for (int i = 1; i <= n; i++)
    {
      printf("i = %d, koszt = %lld\n", i, cost[i]);
    }
    printf("\n");*/
    start = best.second;
    printf("%d ", best.second);
  }
  
  
  return 0;
}