func_code_string: #include <bits/stdc++.h>   using namespace std;   const int N = 200000;   int H[N];   vector<int> g[N], b[N];   int ans[N];   int n, q;   map<int, set<pair<int, int> > > m;   void dfs(int v, int h = 0, int p = -1) {     ans[v] = -1;     H[v] = h;     for (auto i : b[v]) {       if (!m[i].empty()) {         auto t = *m[i].begin();         if (ans[v] == -1 || H[ans[v]] < -t.first) ans[v] = t.second;       }       m[i].insert({-h, v});     }     for (auto u : g[v]) {       if (p != u) {         dfs(u, h + 1, v);       }     }     for (auto i : b[v]) {       m[i].erase({-h, v});     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cin >> n >> q;     for (int j = 1; j <= n; j++) {       int w;       cin >> w;       for (int i = 2; i * i <= w; i++) {         if (w % i == 0) {           b[j].push_back(i);           while (w % i == 0) w /= i;         }       }       if (w > 1) b[j].push_back(w);     }     for (int i = 1; i < n; i++) {       int u, v;       cin >> u >> v;       g[u].push_back(v);       g[v].push_back(u);     }     dfs(1);     while (q--) {       int t;       cin >> t;       if (t == 2) {         int v, w;         cin >> v >> w;         b[v].clear();         for (int i = 2; i * i <= w; i++) {           if (w % i == 0) {             b[v].push_back(i);             while (w % i == 0) w /= i;           }         }         if (w > 1) b[v].push_back(w);         dfs(1);       } else {         int v;         cin >> v;         cout << ans[v] << endl;       }     }   }   