Adding junction tree algorithm