/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|      0|  auto operator+(const Affine &t) const -> Affine {
   12|      0|    u32 x = (u64(a) * t.a) % P;
   13|      0|    u32 y = (u64(a) * t.b + b) % P;
   14|      0|    u32 z = (u64(t.a) * c + t.c) % P;
   15|      0|    return {x, y, z};
   16|      0|  }
   17|      2|  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|      3|def reverse(int x) -> void {
   30|      3|  node[x].rev ^= 1;
   31|      3|  std::swap(node[x].aff.b, node[x].aff.c);
   32|      3|}
   33|       |
   34|      3|def pushdown(int x) -> void {
   35|      3|  if (node[x].rev) {
  ------------------
  |  Branch (35:7): [True: 33.33%, False: 66.67%]
  ------------------
   36|      1|    std::swap(node[x].ch[0], node[x].ch[1]);
   37|      1|    node[node[x].ch[0]].k = 0;
   38|      1|    node[node[x].ch[1]].k = 1;
   39|      1|    reverse(node[x].ch[0]);
   40|      1|    reverse(node[x].ch[1]);
   41|      1|    node[x].rev = 0;
   42|      1|  }
   43|      3|}
   44|       |
   45|      0|def maintain(int x) -> void {
   46|      0|  node[x].aff = node[node[x].ch[0]].aff +
   47|      0|                Affine{node[x].a, node[x].b, node[x].b} +
   48|      0|                node[node[x].ch[1]].aff;
   49|      0|}
   50|       |
   51|      0|def rotateup(int x) -> void {
   52|      0|  int p = node[x].p;
   53|      0|  int g = node[p].p;
   54|      0|  int k = node[x].k;
   55|      0|  int t = node[p].k;
   56|      0|  node[node[x].ch[k ^ 1]].p = p;
   57|      0|  node[node[x].ch[k ^ 1]].k = k;
   58|      0|  node[p].ch[k] = node[x].ch[k ^ 1];
   59|      0|  node[p].p = x;
   60|      0|  node[p].k = k ^ 1;
   61|      0|  node[x].ch[k ^ 1] = p;
   62|      0|  node[x].p = g;
   63|      0|  node[x].k = t;
   64|      0|  if (t != -1) {
  ------------------
  |  Branch (64:7): [True: 0.00%, False: 0.00%]
  ------------------
   65|      0|    node[g].ch[t] = x;
   66|      0|  }
   67|      0|  maintain(p);
   68|      0|}
   69|       |
   70|      3|def is_root(int x) -> bool { return node[x].k == -1; }
   71|       |
   72|      3|def splay(int x) -> void {
   73|      3|  pushdown(x);
   74|      3|  while (!is_root(x)) {
  ------------------
  |  Branch (74:10): [True: 0.00%, False: 100.00%]
  ------------------
   75|      0|    if (int p = node[x].p; is_root(p)) {
  ------------------
  |  Branch (75:28): [True: 0.00%, False: 0.00%]
  ------------------
   76|      0|      pushdown(p);
   77|      0|      pushdown(x);
   78|      0|      rotateup(x);
   79|      0|    } else {
   80|      0|      int g = node[p].p;
   81|      0|      pushdown(g);
   82|      0|      pushdown(p);
   83|      0|      pushdown(x);
   84|      0|      if (node[x].k == node[p].k) {
  ------------------
  |  Branch (84:11): [True: 0.00%, False: 0.00%]
  ------------------
   85|      0|        rotateup(p);
   86|      0|        rotateup(x);
   87|      0|      } else {
   88|      0|        rotateup(x);
   89|      0|        rotateup(x);
   90|      0|      }
   91|      0|    }
   92|      0|  }
   93|      3|}
   94|       |
   95|      2|def access(int x) -> void {
   96|      2|  splay(x);
   97|      2|  node[node[x].ch[1]].k = -1;
   98|      2|  node[x].ch[1] = 0;
   99|      2|  while (int p = node[x].p) {
  ------------------
  |  Branch (99:14): [True: 0.00%, False: 100.00%]
  ------------------
  100|      0|    splay(p);
  101|      0|    node[node[p].ch[1]].k = -1;
  102|      0|    node[p].ch[1] = x;
  103|      0|    node[x].k = 1;
  104|      0|    rotateup(x);
  105|      0|  }
  106|      2|}
  107|       |
  108|       |int head[N];
  109|       |struct {
  110|       |  int to;
  111|       |  int next;
  112|       |} edge[N * 2];
  113|       |
  114|      1|def build(int u, int p) -> void {
  115|      1|  for (int e = head[u]; e; e = edge[e].next) {
                                         ^0
  ------------------
  |  Branch (115:25): [True: 0.00%, False: 100.00%]
  ------------------
  116|      0|    int v = edge[e].to;
  117|      0|    if (v != p) {
  ------------------
  |  Branch (117:9): [True: 0.00%, False: 0.00%]
  ------------------
  118|      0|      build(v, u);
  119|      0|      node[v + 1].p = u + 1;
  120|      0|    }
  121|      0|  }
  122|      1|}
  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|      2|  for (int i = 1; i <= n; ++i) {
                                        ^1
  ------------------
  |  Branch (135:19): [True: 50.00%, False: 50.00%]
  ------------------
  136|      1|    node[i] = {.k = -1};
  137|      1|    u32 a = node[i].a = rd.uw();
  138|      1|    u32 b = node[i].b = rd.uw();
  139|      1|    node[i].aff = {a, b, b};
  140|      1|  }
  141|      1|  for (int i = 1; i != n; ++i) {
                                        ^0
  ------------------
  |  Branch (141:19): [True: 0.00%, False: 100.00%]
  ------------------
  142|      0|    int u = rd.uh();
  143|      0|    int v = rd.uh();
  144|      0|    edge[i * 2 | 0] = {v, head[u]}, head[u] = i * 2 | 0;
  145|      0|    edge[i * 2 | 1] = {u, head[v]}, head[v] = i * 2 | 1;
  146|      0|  }
  147|      1|  build(0, 0);
  148|      3|  while (q--) {
  ------------------
  |  Branch (148:10): [True: 66.67%, False: 33.33%]
  ------------------
  149|      2|    let t = rd.u1();
  150|      2|    if (t == 0) {
  ------------------
  |  Branch (150:9): [True: 0.00%, False: 100.00%]
  ------------------
  151|      0|      int u = rd.uh() + 1;
  152|      0|      int v = rd.uh() + 1;
  153|      0|      access(u);
  154|      0|      reverse(u);
  155|      0|      access(v);
  156|      0|      node[node[v].ch[0]].p = 0;
  157|      0|      node[node[v].ch[0]].k = -1;
  158|      0|      node[v].ch[0] = 0;
  159|      0|      int w = rd.uh() + 1;
  160|      0|      int x = rd.uh() + 1;
  161|      0|      access(w);
  162|      0|      reverse(w);
  163|      0|      node[w].p = x;
  164|      0|    }
  165|      2|    if (t == 1) {
  ------------------
  |  Branch (165:9): [True: 50.00%, False: 50.00%]
  ------------------
  166|      1|      int u = rd.uh() + 1;
  167|      1|      node[u].a = rd.uw();
  168|      1|      node[u].b = rd.uw();
  169|      1|      splay(u);
  170|      1|    }
  171|      2|    if (t == 2) {
  ------------------
  |  Branch (171:9): [True: 50.00%, False: 50.00%]
  ------------------
  172|      1|      int u = rd.uh() + 1;
  173|      1|      int v = rd.uh() + 1;
  174|      1|      u32 x = rd.uw();
  175|      1|      access(v);
  176|      1|      reverse(v);
  177|      1|      access(u);
  178|      1|      x = Affine{node[u].a, node[u].b, node[u].b} + x;
  179|      1|      x = node[node[u].ch[0]].aff + x;
  180|      1|      wt.ud(x);
  181|      1|    }
  182|      2|  }
  183|      1|  return 0;
  184|      1|}