Practice/Meta/Optimize Meeting Point for Friends in a Graph
CodingMust
You are organizing a meetup for a group of friends who are currently at different locations within a city network. The city is represented as an undirected graph where nodes represent locations and edges represent direct paths between locations. Each edge has equal weight, meaning traveling along any edge takes exactly one unit of time.
Given the positions of all friends and a list of potential meeting venues, determine which venue minimizes the total travel time for all friends combined. Return the node number of the optimal meeting location. If multiple venues have the same minimal total travel time, return the one with the smallest node number.
2 <= n <= 1000 (number of nodes in the graph)1 <= edges.length <= min(n * (n-1) / 2, 5000) (number of edges)1 <= friends.length <= 100 (number of friends)1 <= meetingPoints.length <= 100 (number of potential venues)0 <= friends[i], meetingPoints[i] < nExample 1:
` Input: n = 4 edges = [[0,1],[1,2],[2,3]] friends = [0,3] meetingPoints = [1,2]
Output: 1
Explanation:
Example 2:
` Input: n = 5 edges = [[0,1],[1,2],[2,3],[3,4]] friends = [0,2,4] meetingPoints = [1,2,3]
Output: 2
Explanation:
Example 3:
` Input: n = 3 edges = [[0,1]] friends = [0,2] meetingPoints = [1]
Output: 1
Explanation: