You are given a tree of machines (nodes) where each node can only communicate with its direct parent and children through asynchronous messages. The tree is described by a parent array: for node i, parent[i] is its parent index (-1 for the root). Your task is to implement two independent aggregation operations that must run on this distributed cluster without global knowledge:
You may only add code inside the receiveMessage(message) handler that each node already exposes. The provided messaging primitives are:
When the algorithm finishes, the root must be able to print the total count and the topology string. The whole process must be initiated by the root sending initial messages to its children and must work for arbitrary tree shapes up to the given constraints.