```go
package main
import (
"bufio"
"container/heap"
"fmt"
"os"
"strings"
)
type entry struct {
pri int64
id int
}
type pq []entry
func (h pq) Len() int { return len(h) }
func (h pq) Less(i, j int) bool { return h[i].pri < h[j].pri }
func (h pq) Swap(i, j int) { h[i], h[j] = h[j], h[i] }
func (h *pq) Push(x interface{}) {
*h = pq(append([]entry(*h), x.(entry)))
}
func (h *pq) Pop() interface{} {
old := *h
n := len(old)
x := old[n-1]
*h = pq(old[0 : n-1])
return x
}
var (
sz []int
sub_sum []int64
parent []int
a []int64
adj [][]int
child_heaps []pq
child_sets []map[int]bool
)
func compute_pri(s int, id int) int64 {
return int64(s)<<32 | int64(1000000-id)
}
func find_heavy(x int) int {
h := &child_heaps[x]
for h.Len() > 0 {
top := (*h)[0]
cand := top.id
_, ok := child_sets[x][cand]
if !ok {
heap.Pop(h)
continue
}
cur_pri := compute_pri(sz[cand], cand)
if -top.pri != cur_pri {
heap.Pop(h)
continue
}
return cand
}
return 0
}
func dfs(u, p int) {
parent[u] = p
sz[u] = 1
sub_sum[u] = a[u]
for _, v := range adj[u] {
if v != p {
dfs(v, u)
sz[u] += sz[v]
sub_sum[u] += sub_sum[v]
}
}
}
func main() {
in := bufio.NewReader(os.Stdin)
var n, m int
fmt.Fscan(in, &n, &m)
a = make([]int64, n+1)
for i := 1; i <= n; i++ {
fmt.Fscan(in, &a[i])
}
adj = make([][]int, n+1)
for i := 0; i < n-1; i++ {
var u, v int
fmt.Fscan(in, &u, &v)
adj[u] = append(adj[u], v)
adj[v] = append(adj[v], u)
}
parent = make([]int, n+1)
sz = make([]int, n+1)
sub_sum = make([]int64, n+1)
dfs(1, 0)
child_heaps = make([]pq, n+1)
child_sets = make([]map[int]bool, n+1)
for i := 0; i <= n; i++ {
child_heaps[i] = pq(make([]entry, 0))
child_sets[i] = make(map[int]bool)
}
for u := 1; u <= n; u++ {
for _, v := range adj[u] {
if parent[v] == u {
child_sets[u][v] = true
pri := compute_pri(sz[v], v)
heap.Push(&child_heaps[u], entry{-pri, v})
}
}
}
var answers []string
for qi := 0; qi < m; qi++ {
var t, x int
fmt.Fscan(in, &t, &x)
if t == 1 {
answers = append(answers, fmt.Sprint(sub_sum[x]))
} else {
if len(child_sets[x]) == 0 {
continue
}
son := find_heavy(x)
if son == 0 {
continue
}
fa := parent[x]
old_size_x := sz[x]
old_size_s := sz[son]
old_sum_x := sub_sum[x]
old_sum_s := sub_sum[son]
delete(child_sets[x], son)
delete(child_sets[fa], x)
child_sets[fa][son] = true
child_sets[son][x] = true
parent[son] = fa
parent[x] = son
sz[x] = old_size_x - old_size_s
sub_sum[x] = old_sum_x - old_sum_s
sz[son] = old_size_x
sub_sum[son] = old_sum_x
pri_x := compute_pri(sz[x], x)
heap.Push(&child_heaps[son], entry{-pri_x, x})
pri_s := compute_pri(sz[son], son)
heap.Push(&child_heaps[fa], entry{-pri_s, son})
}
}
fmt.Println(strings.Join(answers, "\n"))
}
```