func_code_string: #include <bits/stdc++.h>   using namespace std;   template <class T>   bool umin(T& a, T b) {     if (a > b) {       a = b;       return 1;     }     return 0;   }   template <class T>   bool umax(T& a, T b) {     if (a < b) {       a = b;       return 1;     }     return 0;   }   long long a, b, c, type, ric[300007], par[300007], cost[300007], d[300007], n,       m, lvl[300007], P[300007][20 * 2];   vector<pair<long long, long long> > E[300007];   pair<pair<long long, long long>, long long> way[300007];   long long atabul(long long x) {     if (ric[x] == x) return x;     return ric[x] = atabul(ric[x]);   }   void dfs(long long x, long long y, long long z) {     lvl[x] = lvl[y] + 1;     P[x][0] = y;     cost[x] = z;     if (z == 1) {       ric[x] = y;       atabul(x);     }     for (int i = 0; i < int(E[x].size()); i++)       if (E[x][i].first != y) dfs(E[x][i].first, x, E[x][i].second);   }   void build_table() {     for (int j = 1; j <= 20; j++)       for (int i = 1; i <= n; i++)         if (P[i][j - 1] > 0) P[i][j] = P[P[i][j - 1]][j - 1];   }   void form_LCA() {     for (int i = 0; i <= n; i++)       for (int j = 0; j <= 20; j++) P[i][j] = -1;     dfs(1, 0, 0);     build_table();   }   long long LCA(long long x, long long y) {     if (lvl[x] < lvl[y]) swap(x, y);     for (int i = 20; i >= 0; i--)       if (lvl[x] - (1 << i) >= lvl[y]) x = P[x][i];     if (x == y) return x;     for (int i = 20; i >= 0; i--)       if (P[x][i] > 0 && P[x][i] != P[y][i]) x = P[x][i], y = P[y][i];     return P[x][0];   }   int main() {     scanf( %lld%lld , &n, &m);     ric[n] = n;     for (int i = 1; i < n; i++) {       scanf( %lld%lld%lld , &a, &b, &c);       E[a].push_back(make_pair(b, c));       E[b].push_back(make_pair(a, c));       ric[i] = i;       way[i] = {{a, b}, c};     }     form_LCA();     while (m--) {       scanf( %lld , &type);       if (type == 1) {         scanf( %lld%lld%lld , &a, &b, &c);         long long tr = LCA(a, b);         while (atabul(a) != atabul(tr) && c > 0) {           if (cost[a] == 1) {             a = atabul(a);             continue;           }           c /= cost[a];           a = P[a][0];         }         while (atabul(b) != atabul(tr) && c > 0) {           if (cost[b] == 1) {             b = atabul(b);             continue;           }           c /= cost[b];           b = P[b][0];         }         printf( %lld n , c);       } else {         scanf( %lld%lld , &a, &b);         long long qm = way[a].first.first, gr = way[a].first.second;         if (lvl[qm] < lvl[gr]) swap(qm, gr);         cost[qm] = b;         if (b == 1) {           ric[qm] = gr;           atabul(qm);         }       }     }     return 0;   }   