Catch invalid node IDs given in cluster hierarchy.

Also improves the efficiency of code that counts node presence in
clusters to only walk the hierarchy once.