Skip to content

Instantly share code, notes, and snippets.

@Chillee
Last active December 21, 2018 16:13
Show Gist options
  • Select an option

  • Save Chillee/710def28a2671cc12468934c0332fd98 to your computer and use it in GitHub Desktop.

Select an option

Save Chillee/710def28a2671cc12468934c0332fd98 to your computer and use it in GitHub Desktop.
Random Snippets (Stuff that's not reusable but were painful to write that I wrote nicely and am happy with)
pair<bool, array<int, 2>> canMerge(array<int, 4> pts) {
auto cmp = [&](int a, int b) { return make_pair(lca.depth[a], a) > make_pair(lca.depth[b], b); };
sort(pts.begin(), pts.end(), cmp);
do {
if (lca.dist(pts[0], pts[1]) + lca.dist(pts[1], pts[2]) + lca.dist(pts[2], pts[3]) == lca.dist(pts[0], pts[3]))
return {true, {pts[0], pts[3]}};
} while (next_permutation(pts.begin() + 1, pts.end(), cmp));
return {false, {0, 0}};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment