Learn
Practice
Interview
Resources
Newsletter
F
Toggle theme
0
F
0
Toggle menu
Animations
← Back to All Animations
Heavy-Light Decomposition
Bookmark
Input
Standard (7 nodes)
Deep left (9 nodes)
Path graph (5 nodes)
Wide root (7 nodes)
Custom
edges
=
[[0,1],[0,2],[1,3],[1,4],[2,5],[3,6]]
,
numNodes
=
7
,
queryU
=
6
,
queryV
=
5
0
1
2
3
4
5
6
Unprocessed
Processed
Active
Heavy/Path
Heavy Edge
Light
0
1
2
3
4
5
6
Unprocessed
Processed
Active
Heavy/Path
Heavy Edge
Light
0
1
2
3
4
5(1)
6(1)
Unprocessed
Processed
Active
Heavy/Path
Heavy Edge
Light
0
1
2
3(2)
4(1)
5(1)
6(1)
Unprocessed
Processed
Active
Heavy/Path
Heavy Edge
Light
0(7)
1(4)
2(2)
3(2)
4(1)
5(1)
6(1)
Unprocessed
Processed
Active
Heavy/Path
Heavy Edge
Light
0(7)
1(4)
2(2)
3(2)
4(1)
5(1)
6(1)
Unprocessed
Processed
Active
Heavy/Path
Heavy Edge
Light
0(7)
1(4)
2(2)
3(2)
4(1)
5(1)
6(1)
Unprocessed
Processed
Active
Heavy/Path
Heavy Edge
Light
0(7)
1(4)
2(2)
3(2)
4(1)
5(1)
6(1)
Unprocessed
Processed
Active
Heavy/Path
Heavy Edge
Light
0[C0]
1[C0]
2[C1]
3[C0]
4[C2]
5[C1]
6[C0]
Unprocessed
Processed
Active
Heavy/Path
Heavy Edge
Light
0[C0]
1[C0]
2[C1]
3[C0]
4[C2]
5[C1]
6[C0]
Unprocessed
Processed
Active
Heavy/Path
Heavy Edge
Light
0[C0]
1[C0]
2[C1]
3[C0]
4[C2]
5[C1]
6[C0]
Unprocessed
Processed
Active
Heavy/Path
Heavy Edge
Light
algo
master
.
io
Step:
Start: We have a rooted tree with root = 0. We will perform Heavy-Light Decomposition.
0 / 24
Input
Standard (7 nodes)
Deep left (9 nodes)
Path graph (5 nodes)
Wide root (7 nodes)
Custom
edges
=
[[0,1],[0,2],[1,3],[1,4],[2,5],[3,6]]
,
numNodes
=
7
,
queryU
=
6
,
queryV
=
5
0 / 24
algo
master
.
io
Step:
Start: We have a rooted tree with root = 0. We will perform Heavy-Light Decomposition.