/tmp/solutions/build/dynamic_tree_vertex_set_path_composite-main.cpp:
    1|       |#include <common.h>
    2|       |prelude;
    3|       |
    4|       |namespace {
    5|       |
    6|       |constexpr int N = 200001;
    7|       |constexpr u32 P = 998244353;
    8|       |
    9|       |struct Affine {
   10|       |  u32 a, b, c;
   11|  3.73k|  auto operator+(const Affine &t) const -> Affine {
   12|  3.73k|    u32 x = (u64(a) * t.a) % P;
   13|  3.73k|    u32 y = (u64(a) * t.b + b) % P;
   14|  3.73k|    u32 z = (u64(t.a) * c + t.c) % P;
   15|  3.73k|    return {x, y, z};
   16|  3.73k|  }
   17|    154|  auto operator+(const u32 &t) const -> u32 { return (u64(a) * t + b) % P; }
   18|       |};
   19|       |struct Node {
   20|       |  u32 a;
   21|       |  u32 b;
   22|       |  Affine aff;
   23|       |  int p;
   24|       |  int ch[2];
   25|       |  i8 rev;
   26|       |  i8 k;
   27|       |} node[N];
   28|       |
   29|  2.22k|def reverse(int x) -> void {
   30|  2.22k|  node[x].rev ^= 1;
   31|  2.22k|  std::swap(node[x].aff.b, node[x].aff.c);
   32|  2.22k|}
   33|       |
   34|  3.06k|def pushdown(int x) -> void {
   35|  3.06k|  if (node[x].rev) {
  ------------------
  |  Branch (35:7): [True: 32.45%, False: 67.55%]
  ------------------
   36|    995|    std::swap(node[x].ch[0], node[x].ch[1]);
   37|    995|    node[node[x].ch[0]].k = 0;
   38|    995|    node[node[x].ch[1]].k = 1;
   39|    995|    reverse(node[x].ch[0]);
   40|    995|    reverse(node[x].ch[1]);
   41|    995|    node[x].rev = 0;
   42|    995|  }
   43|  3.06k|}
   44|       |
   45|  1.86k|def maintain(int x) -> void {
   46|  1.86k|  node[x].aff = node[node[x].ch[0]].aff +
   47|  1.86k|                Affine{node[x].a, node[x].b, node[x].b} +
   48|  1.86k|                node[node[x].ch[1]].aff;
   49|  1.86k|}
   50|       |
   51|  1.86k|def rotateup(int x) -> void {
   52|  1.86k|  int p = node[x].p;
   53|  1.86k|  int g = node[p].p;
   54|  1.86k|  int k = node[x].k;
   55|  1.86k|  int t = node[p].k;
   56|  1.86k|  node[node[x].ch[k ^ 1]].p = p;
   57|  1.86k|  node[node[x].ch[k ^ 1]].k = k;
   58|  1.86k|  node[p].ch[k] = node[x].ch[k ^ 1];
   59|  1.86k|  node[p].p = x;
   60|  1.86k|  node[p].k = k ^ 1;
   61|  1.86k|  node[x].ch[k ^ 1] = p;
   62|  1.86k|  node[x].p = g;
   63|  1.86k|  node[x].k = t;
   64|  1.86k|  if (t != -1) {
  ------------------
  |  Branch (64:7): [True: 21.96%, False: 78.04%]
  ------------------
   65|    410|    node[g].ch[t] = x;
   66|    410|  }
   67|  1.86k|  maintain(p);
   68|  1.86k|}
   69|       |
   70|  2.74k|def is_root(int x) -> bool { return node[x].k == -1; }
   71|       |
   72|  1.29k|def splay(int x) -> void {
   73|  1.29k|  pushdown(x);
   74|  2.01k|  while (!is_root(x)) {
  ------------------
  |  Branch (74:10): [True: 35.98%, False: 64.02%]
  ------------------
   75|    725|    if (int p = node[x].p; is_root(p)) {
  ------------------
  |  Branch (75:28): [True: 55.03%, False: 44.97%]
  ------------------
   76|    399|      pushdown(p);
   77|    399|      pushdown(x);
   78|    399|      rotateup(x);
   79|    399|    } else {
   80|    326|      int g = node[p].p;
   81|    326|      pushdown(g);
   82|    326|      pushdown(p);
   83|    326|      pushdown(x);
   84|    326|      if (node[x].k == node[p].k) {
  ------------------
  |  Branch (84:11): [True: 34.66%, False: 65.34%]
  ------------------
   85|    113|        rotateup(p);
   86|    113|        rotateup(x);
   87|    213|      } else {
   88|    213|        rotateup(x);
   89|    213|        rotateup(x);
   90|    213|      }
   91|    326|    }
   92|    725|  }
   93|  1.29k|}
   94|       |
   95|    391|def access(int x) -> void {
   96|    391|  splay(x);
   97|    391|  node[node[x].ch[1]].k = -1;
   98|    391|  node[x].ch[1] = 0;
   99|  1.20k|  while (int p = node[x].p) {
  ------------------
  |  Branch (99:14): [True: 67.61%, False: 32.39%]
  ------------------
  100|    816|    splay(p);
  101|    816|    node[node[p].ch[1]].k = -1;
  102|    816|    node[p].ch[1] = x;
  103|    816|    node[x].k = 1;
  104|    816|    rotateup(x);
  105|    816|  }
  106|    391|}
  107|       |
  108|       |int head[N];
  109|       |struct {
  110|       |  int to;
  111|       |  int next;
  112|       |} edge[N * 2];
  113|       |
  114|    193|def build(int u, int p) -> void {
  115|    577|  for (int e = head[u]; e; e = edge[e].next) {
                                         ^384
  ------------------
  |  Branch (115:25): [True: 66.55%, False: 33.45%]
  ------------------
  116|    384|    int v = edge[e].to;
  117|    384|    if (v != p) {
  ------------------
  |  Branch (117:9): [True: 50.00%, False: 50.00%]
  ------------------
  118|    192|      build(v, u);
  119|    192|      node[v + 1].p = u + 1;
  120|    192|    }
  121|    384|  }
  122|    193|}
  123|       |
  124|       |} // namespace
  125|       |
  126|      1|int main() {
  127|      1|  node[0].aff.a = 1;
  128|      1|  rd rd;
  129|      1|  wt wt;
  130|      1|  int n = rd.uh();
  131|      1|  int q = rd.uh();
  132|      1|#ifdef LOCAL
  133|      1|  std::memset(head, 0, 4 * n);
  134|      1|#endif
  135|    194|  for (int i = 1; i <= n; ++i) {
                                        ^193
  ------------------
  |  Branch (135:19): [True: 99.48%, False: 0.52%]
  ------------------
  136|    193|    node[i] = {.k = -1};
  137|    193|    u32 a = node[i].a = rd.uw();
  138|    193|    u32 b = node[i].b = rd.uw();
  139|    193|    node[i].aff = {a, b, b};
  140|    193|  }
  141|    193|  for (int i = 1; i != n; ++i) {
                                        ^192
  ------------------
  |  Branch (141:19): [True: 99.48%, False: 0.52%]
  ------------------
  142|    192|    int u = rd.uh();
  143|    192|    int v = rd.uh();
  144|    192|    edge[i * 2 | 0] = {v, head[u]}, head[u] = i * 2 | 0;
  145|    192|    edge[i * 2 | 1] = {u, head[v]}, head[v] = i * 2 | 1;
  146|    192|  }
  147|      1|  build(0, 0);
  148|    240|  while (q--) {
  ------------------
  |  Branch (148:10): [True: 99.58%, False: 0.42%]
  ------------------
  149|    239|    let t = rd.u1();
  150|    239|    if (t == 0) {
  ------------------
  |  Branch (150:9): [True: 33.05%, False: 66.95%]
  ------------------
  151|     79|      int u = rd.uh() + 1;
  152|     79|      int v = rd.uh() + 1;
  153|     79|      access(u);
  154|     79|      reverse(u);
  155|     79|      access(v);
  156|     79|      node[node[v].ch[0]].p = 0;
  157|     79|      node[node[v].ch[0]].k = -1;
  158|     79|      node[v].ch[0] = 0;
  159|     79|      int w = rd.uh() + 1;
  160|     79|      int x = rd.uh() + 1;
  161|     79|      access(w);
  162|     79|      reverse(w);
  163|     79|      node[w].p = x;
  164|     79|    }
  165|    239|    if (t == 1) {
  ------------------
  |  Branch (165:9): [True: 34.73%, False: 65.27%]
  ------------------
  166|     83|      int u = rd.uh() + 1;
  167|     83|      node[u].a = rd.uw();
  168|     83|      node[u].b = rd.uw();
  169|     83|      splay(u);
  170|     83|    }
  171|    239|    if (t == 2) {
  ------------------
  |  Branch (171:9): [True: 32.22%, False: 67.78%]
  ------------------
  172|     77|      int u = rd.uh() + 1;
  173|     77|      int v = rd.uh() + 1;
  174|     77|      u32 x = rd.uw();
  175|     77|      access(v);
  176|     77|      reverse(v);
  177|     77|      access(u);
  178|     77|      x = Affine{node[u].a, node[u].b, node[u].b} + x;
  179|     77|      x = node[node[u].ch[0]].aff + x;
  180|     77|      wt.ud(x);
  181|     77|    }
  182|    239|  }
  183|      1|  return 0;
  184|      1|}