Meeting Point
Time limit25sMemory limit1024 MB
Given an odd-sized hidden tree queried only by three-node median (meeting point) queries, find the node minimizing the total distance to all friends.
- Level
Hard8 of 10
- Topics
- Tree, Divide and conquer, Implementation
- Solved
- No attempts yet
Problem
friends each live on their own node of a tree with nodes, where is odd. A tree is a connected graph with exactly edges.
The friends want to meet at one node of the tree. They have decided to meet at the node that minimizes the sum of distances to all friends, and they asked you to find this optimal meeting point. The distance between two nodes and is the number of edges on the path between them. Formally, you want to find the node that minimizes .
The friends do not remember what the tree looks like. They do remember this: given three different friends , , and , they meet (when only those three are present) at the node that minimizes . Note that is not necessarily one of , , or .
The tree is not given in the input. You may ask up to questions of the form: where do friends , , and meet? Use these questions to find the optimal meeting point.

Illustration of the example tree. Node 2 is the optimal meeting point.