Last active
December 21, 2018 16:13
-
-
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)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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