function [A] = p1todense(p, alpha, beta)
% Convert a tree data structure to a dense representation
% as described in problem 1.

A = diag(alpha);
n = length(alpha);
for k = 2:n
A(k,p(k)) = beta(k);
A(p(k),k) = beta(k);
end