← 返回 openai 的题目列表Distributed Topology Reconstruction via Async Messages
类型:online_judge
Reconstruct Distributed Tree Topology (Async Messaging)
Same distributed tree and communication model as before:
No direct access to the global structure; only sendAsyncMessage(nodeId, message) and each node's receiveMessage(fromNodeId, message).
You must design the message protocol and maintain per-request state on each node.
Goal
When a topology query is initiated from root, the root outputs a topology string like:
1(2(4,5),3(6))
Rules:
Print node id.
If a node has children, print them in parentheses separated by commas.
Leaf nodes print only their id.
Requirements
Use async messages only.
Distinguish request vs response.
Handle concurrent message arrivals.
Root prints the final string after collecting all results.
Example
1 -> {2,3}, 2 -> {4,5}, 3 -> {6}
Output: 1(2(4,5),3(6))
Example
Input
root=1, edges: 1->[]
Output
1