Graph problems: connect by NOCYCLE prior replacement in SQL server?
To improve select performance store possible paths between nodes in a permanent table
TABLE T_Hops_Path( FromNode, ToNode, HopCount, TotalDistance)
If your tree structure does not change often you can write a stored procedure that generates this table every N hours.