Count Your Cousins

From programming_contest
Jump to navigation Jump to search

The only real challenge here is building the graph. You just have to who you're adding children to. Once you've built the graph, you go up one level and memorize your parent. Then go up another level and iterate through all the children's children (skipping your parent) and count them.