Skip to content

Commit

Permalink
Fix treetopologyex.11.cpp (#26)
Browse files Browse the repository at this point in the history
* Update treetopologyex.11.cpp

* Update treetopologyex.11.cpp
  • Loading branch information
Sprdalo authored Jun 14, 2024
1 parent 179561d commit b957cf8
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions trees/treetopologyex.11.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ struct tree_topology_ex : tree_topology {

int kth(int x, int y, int k) {
int z = lca(x, y);
if (k <= d[x] - d[y]) {
if (k <= d[x] - d[z]) {
return lift(x, k);
} else {
return lift(y, d[x] + d[y] - 2*d[z] - k);
Expand All @@ -100,7 +100,7 @@ struct tree_topology_ex : tree_topology {
/*snippet-end*/

int main() {
tree_topology_ex tt({{0, 1}, {1, 2}, {1, 3}}, 3);
tree_topology_ex tt({{0, 1}, {1, 2}, {1, 3}, {2, 4}, {4, 5}, {5, 6}, {3, 7}}, 3);

return tt.lca(2, 3) != 1 || tt.distance(2, 3) != 2;
return tt.lca(2, 3) != 1 || tt.distance(2, 3) != 2 || tt.kth(6, 7, 3) != 2;
}

0 comments on commit b957cf8

Please sign in to comment.