How can I find all equal paths in a degenerate tree from a certain starting vertex?
I have degenerate tree
(it looks like an array or a double linked list). For example, this tree:
Each edge has some weight. I want to find all equal paths that start at each vertex.
Let the edges have the following weights (this is just an example):
a-b = 3
b-c = 1
c-d = 1
d-e = 1
Then:
- The vertex
A
has no equal path (no vertex on the left side). - The vertex
B
has one equal pair. The pathB-A
is equal to the pathB-E
(3 == 3)
. - The vertex
C
has one equal pair. The pathB-C
is equal to the pathC-D
(1 == 1)
. - The vertex
D
has one equal pair. The pathC-D
is equal to the pathD-E
(1 == 1)
. - The vertex
E
has no equal path (no vertex on the right side).
I am implementing a simple algorithm that works in O(n^2)
. But it's too slow for me.
+3
source to share
No one has answered this question yet
See similar questions:
or similar: