Skip to content

Bug of Euler Tour Tree #18

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
MiSawa opened this issue Mar 6, 2021 · 0 comments · May be fixed by #19
Open

Bug of Euler Tour Tree #18

MiSawa opened this issue Mar 6, 2021 · 0 comments · May be fixed by #19

Comments

@MiSawa
Copy link

MiSawa commented Mar 6, 2021

Challenge case

int main() {
  euler_tour_tree ETT;

  auto a = ETT.make_node(1 << 0);
  auto b = ETT.make_node(1 << 1);
  auto c = ETT.make_node(1 << 2);

  auto ba = ETT.link(b, a);
  auto ca = ETT.link(c, a);
  ETT.cut(ba);

  // Now components are {a, c} and {b}.
  // Since b is a singleton component, there should be no child.
  cout << b->ch[0] << " " << b->ch[1] << endl; // expects 0 0

  // Something undefined happens...
  auto ab = ETT.link(a, b);
  cout << ETT.sum_in_component(a) << endl; // expects 0b111
  return 0;
}

Cause

Here's the current implementation of cut operation.

void cut(node *uv) {
splay(uv); disconnect(uv,1); splay(uv->r);
join(disconnect(uv,0), disconnect(uv->r,1));
delete uv, uv->r;
}

This implementation assumes that uv->r is in the right subtree of uv after splay(uv). This assumption is true right after link(u, v), but not maintained in the following operations.

MiSawa added a commit to MiSawa/algorithm that referenced this issue Mar 6, 2021
@MiSawa MiSawa linked a pull request Mar 6, 2021 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant