Skip to content

Commit afb1c66

Browse files
committed
Build Failure Update
1 parent 928e7cc commit afb1c66

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

src/main/java/com/thealgorithms/tree/HeavyLightDecomposition.java

+7-3
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ public class HeavyLightDecomposition {
2727
@SuppressWarnings("unchecked")
2828
public HeavyLightDecomposition(int n) {
2929
tree = new ArrayList[n + 1];
30+
for (int i = 0; i <= n; i++) {
31+
tree[i] = new ArrayList<>();
32+
}
3033
parent = new int[n + 1];
3134
depth = new int[n + 1];
3235
subtreeSize = new int[n + 1];
@@ -35,7 +38,6 @@ public HeavyLightDecomposition(int n) {
3538
nodeValue = new int[n + 1];
3639
segmentTree = new int[4 * (n + 1)];
3740
for (int i = 0; i <= n; i++) {
38-
tree[i] = new ArrayList<>();
3941
chainHead[i] = -1;
4042
}
4143
positionIndex = 0;
@@ -89,7 +91,7 @@ private void decompose(int node, int head) {
8991

9092
private void buildSegmentTree(int node, int start, int end) {
9193
if (start == end) {
92-
segmentTree[node] = nodeValue[start];
94+
segmentTree[node] = nodeValue[start];
9395
return;
9496
}
9597
int mid = (start + end) / 2;
@@ -149,7 +151,9 @@ public void initialize(int root, int[] values) {
149151
dfsSize(root, -1);
150152
decompose(root, root);
151153
for (int i = 0; i < values.length; i++) {
152-
nodeValue[position[i]] = values[i];
154+
if (i < positionIndex) {
155+
nodeValue[position[i]] = values[i];
156+
}
153157
}
154158
buildSegmentTree(1, 0, positionIndex - 1);
155159
}

0 commit comments

Comments
 (0)