graph/product: fix subtle interaction between dst and inputs
The optimisation that is applied for undirected graphs is only valid if
the destination graph is also undirected. So we need to check that and only
apply the optimisation when all three graphs are undirected.
@@ -270,7 +270,8 @@ func Modular(dst graph.Builder, a, b graph.Graph) {
_, aUndirected := a.(graph.Undirected)
_, bUndirected := b.(graph.Undirected)
- undirected := aUndirected && bUndirected
+ _, dstUndirected := dst.(graph.Undirected)
+ undirected := aUndirected && bUndirected && dstUndirected
n := len(product)
if undirected {
