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
/*
 * BAN
 * Autor: Szymon Tur
 */

#include <iostream>
#include <vector>

#define LLMIN -9223372036854775807

using namespace std;

struct cena_pd
{
	int w_do;
	long long cena;
};

long long * zarobek;
vector<cena_pd> * graf;

bool * visited;
long long cena_p = 0;
bool droga(int start, int finish, int pop)
{
	int _q = 0;
	visited[start] = true;
	if (pop != -1)
		for (int j = 0;j<graf[pop].size();j++)
			if (graf[pop][j].w_do == start)
			{
				_q = graf[pop][j].cena;
				cena_p += _q;
				break;
			}
	if (start == finish) return true;
	for (int w = 0;w<graf[start].size();w++)
	{
		if (visited[graf[start][w].w_do]) continue;
		if (droga(graf[start][w].w_do, finish, start)) return true;
	}
	cena_p -= _q;
	return false;
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	int n, q;
	cin >> n >> q;
	zarobek = new long long[n];
	visited = new bool[n];
	for (int i = 0;i<n;i++) cin >> zarobek[i];
	graf = new vector<cena_pd>[n];
	int _x, _y;
	long long _c;
	cena_pd _f, _g;
	for (int i = 0;i<n - 1;i++)
	{
		cin >> _x >> _y >> _c;
		_f.w_do = _y - 1;
		_f.cena = _c;
		_g.w_do = _x - 1;
		_g.cena = _c;
		graf[_x - 1].push_back(_f);
		graf[_y - 1].push_back(_g);
	}
	// dla każdego dnia
	int a, w = 0, tw=0;
	vector<int> kol;
	long long max;
	for (int i = 0;i<q;i++)
	{
		cin >> a;
		if (a == 1)
		{
			cin >> _x >> _c;
			zarobek[_x - 1] = _c;
		}
		else
		{
			cin >> _x >> _y >> _c;
			for (int j = 0;j<graf[_x - 1].size();j++)
				if (graf[_x - 1][j].w_do == _y - 1)
				{
					graf[_x - 1][j].cena = _c;
					break;
				}
			for (int j = 0;j<graf[_y - 1].size();j++)
				if (graf[_y - 1][j].w_do == _x - 1)
				{
					graf[_y - 1][j].cena = _c;
					break;
				}

		}
		max = LLMIN;
		for (int j = 0;j<n;j++)
		{
			for (int ss = 0;ss<n;ss++) visited[ss] = false;
			cena_p = 0;
			if (w != j) 
			{
				droga(w, j, -1);
				if (zarobek[j] - cena_p > max)
				{
					tw = j;
					max = zarobek[j] - cena_p;
				}
			}
		}
		w = tw;
		kol.push_back(w + 1);
	}
	for (int i = 0;i<q;i++)
	{
		cout << kol[i] << " ";
	}
	return 0;

}