Reasoning with Probabilistic and Deterministic Graphical Models: Exact Algorithms