public static int Solve2(Tree tree, string target = "shiny gold") => BFSSum(target, tree);
public static int Solve1(Tree tree, string target = "shiny gold") => tree .Select(edge => edge.Key) .Where(node => BFSFind(node, tree, target)) .Count() - 1;
public static int BFSSum(string node, Tree tree) => tree[node].Count() == 0 ? 0 : tree[node].Sum(x => (1 + BFSSum(x.Name, tree)) * x.Count);
public static bool BFSFind(string node, Tree tree, string target) => node.Equals(target) ? true : tree[node] .Select(x => x.Name) .Any(x => BFSFind(x, tree, target));