Skip to content
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

Fix treetopologyex.11.cpp #26

Merged
merged 2 commits into from
Jun 14, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion 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 @@ -102,5 +102,7 @@ struct tree_topology_ex : tree_topology {
int main() {
tree_topology_ex tt({{0, 1}, {1, 2}, {1, 3}}, 3);

cout << tt.kth(2, 3, 1);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Printing a value doesn't really do anything towards the result of the test. You must compare it with the expected value and return 1 if they're different.

Another idea: Since the tree in this test case is quite small, let's add a different one with say, 10 nodes, pick some two vertices whose LCA is not 0, and test every vertex on the path between them by calling kth.


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