コード例 #1
0
 void update() {
   size = 1;
   subtree_value = value;
   if (left != NULL) {
     subtree_value = join_values(subtree_value, left->get_subtree_value());
     size += left->size;
   }
   if (right != NULL) {
     subtree_value = join_values(subtree_value, right->get_subtree_value());
     size += right->size;
   }
 }
コード例 #2
0
 T query(int a, int b) {
   if (!is_connected(a, b)) {
     throw std::runtime_error("Cannot query nodes that are not connected.");
   }
   get_uv(a, b);
   expose(u);
   u->rev = !u->rev;
   expose(v);
   return v->get_subtree_value();
 }