diff --git a/pom.xml b/pom.xml index 604e31212..f3c88c5c5 100644 --- a/pom.xml +++ b/pom.xml @@ -2,7 +2,7 @@ 4.0.0 com.github.btrekkie.connectivity dynamic-connectivity - 0.1.0 + 0.1.1 dynamic-connectivity Data structure for dynamic connectivity in undirected graphs diff --git a/src/main/java/com/github/btrekkie/connectivity/ConnGraph.java b/src/main/java/com/github/btrekkie/connectivity/ConnGraph.java index 4f16deb76..c60b7db2f 100644 --- a/src/main/java/com/github/btrekkie/connectivity/ConnGraph.java +++ b/src/main/java/com/github/btrekkie/connectivity/ConnGraph.java @@ -829,17 +829,22 @@ public class ConnGraph { while (levelVertex1 != null) { EulerTourNode root1 = levelVertex1.arbitraryVisit.root(); EulerTourNode root2 = levelVertex2.arbitraryVisit.root(); - EulerTourNode root; - if (root1.size < root2.size) { - root = root1; - } else { - root = root2; - } - pushForestEdges(root); - replacementEdge = findReplacementEdge(root); - if (replacementEdge != null) { - break; + // Optimization: if hasGraphEdge is false for one of the roots, then there definitely isn't a + // replacement edge at this level + if (root1.hasGraphEdge && root2.hasGraphEdge) { + EulerTourNode root; + if (root1.size < root2.size) { + root = root1; + } else { + root = root2; + } + + pushForestEdges(root); + replacementEdge = findReplacementEdge(root); + if (replacementEdge != null) { + break; + } } // To save space, get rid of trees with one node diff --git a/target/dynamic-connectivity-0.1.0.jar b/target/dynamic-connectivity-0.1.0.jar deleted file mode 100644 index d097c59ba..000000000 Binary files a/target/dynamic-connectivity-0.1.0.jar and /dev/null differ diff --git a/target/dynamic-connectivity-0.1.0-jar-with-dependencies.jar b/target/dynamic-connectivity-0.1.1-jar-with-dependencies.jar similarity index 60% rename from target/dynamic-connectivity-0.1.0-jar-with-dependencies.jar rename to target/dynamic-connectivity-0.1.1-jar-with-dependencies.jar index 509855f6b..9a757a038 100644 Binary files a/target/dynamic-connectivity-0.1.0-jar-with-dependencies.jar and b/target/dynamic-connectivity-0.1.1-jar-with-dependencies.jar differ diff --git a/target/dynamic-connectivity-0.1.1.jar b/target/dynamic-connectivity-0.1.1.jar new file mode 100644 index 000000000..fed9bc68f Binary files /dev/null and b/target/dynamic-connectivity-0.1.1.jar differ