-
Notifications
You must be signed in to change notification settings - Fork 6
Add fast-chu-liu.cpp for directed MST algorithm #61
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
Conversation
Implemented the optimized Edmonds/Chu-Liu algorithm for finding minimum spanning arborescence using lazy skew heaps.
Updated comments for clarity and formatting.
Updated comment to clarify return value when not reachable.
|
Test fallido, por favor corregir. Saludos! |
Updated comments to clarify complexity and status.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
Adds an optimized Minimum Spanning Arborescence (directed MST) implementation using an Edmonds/Chu–Liu variant with lazy skew heaps, and registers it in the content tracker.
Changes:
- Added
fast-chu-liu.cppimplementing anO(E log V)directed MST algorithm returning both total weight and parent array. - Updated
tracker.yamlto include the new snippet undergraphs/misc.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| tracker.yaml | Registers the new directed MST snippet in the content index. |
| content/graphs/misc/fast-chu-liu.cpp | Introduces the optimized Chu–Liu/Edmonds implementation using lazy skew heaps + rollback DSU. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| cyc = merge(cyc, heap[w = path[--qi]]); | ||
| while (uf.unionSet(u, w)); | ||
| u = uf.findSet(u), heap[u] = cyc, seen[u] = -1; | ||
| cycs.push_front({u, t, {&Q[qi], &Q[end]}}); |
Copilot
AI
Jan 27, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The pointer expression &Q[end] is undefined behavior when end == Q.size() (it uses operator[] one-past-the-end). This can happen when qi reaches n on a long path. Construct the subrange using iterators (e.g., Q.begin() + qi / Q.begin() + end) or Q.data() + end to safely represent the end iterator.
| cycs.push_front({u, t, {&Q[qi], &Q[end]}}); | |
| cycs.push_front({u, t, vector<edge>(Q.begin() + qi, Q.begin() + end)}); |
| /* | ||
| *Description:* Minimum spanning arborescence (directed MST), optimized Edmonds/Chu-Liu algorithm using lazy skew heaps | ||
| *Complexity:* $O(E log V)$, returns $(-1, emptyset)$ if not reachable | ||
| *Status:* Tested (Fastest Speedrun) | ||
| */ | ||
| template <class T> struct fast_chu_liu { |
Copilot
AI
Jan 27, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Header comment formatting is inconsistent with other snippets (each line typically starts with *). Lines 3 and 6 currently miss the leading */spacing, which breaks the standard metadata parser/style used elsewhere (e.g., content/graphs/misc/chu-liu.cpp:1-5). Please align the block comment formatting to match the repository convention.
enfermito |
Implemented the optimized Edmonds/Chu-Liu algorithm for finding minimum spanning arborescence using lazy skew heaps.