Add fast-chu-liu.cpp for directed MST algorithm#61
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.
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]}}); |
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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.