Finding a most parsimonious or likely tree in a network with respect to an alignment