8000 Fix comparison in set used by Prim's algorithm · cp-algorithms/cp-algorithms@9a3d4b8 · GitHub
[go: up one dir, main page]

Skip to content

Commit 9a3d4b8

Browse files
committed
Fix comparison in set used by Prim's algorithm
Fixes #527 If the set only compares the weight, then two different edges with the same weight compare equal, and therefor only one of them gets inserted into the set. By comparing also the target node, we fix the problem.
1 parent 2657e19 commit 9a3d4b8

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

src/graph/mst_prim.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ const int INF = 1000000000;
159159
struct Edge {
160160
int w = INF, to = -1;
161161
bool operator<(Edge const& other) const {
162-
return w < other.w;
162+
return make_pair(w, to) < make_pair(other.w, other.to);
163163
}
164164
};
165165

0 commit comments

Comments
 (0)
0