n towns numbered 0 to n - 1, linked by two-way roads: roads[i] = [a, b, w] is a road of length w km between towns a and b. The distance between two towns is the length of the shortest route along the roads.
For each town, count how many **other** towns are at distance at most max_distance from it. Return the town with the fewest such neighbours. If several towns tie, return the one with the largest number.n=3, roads=[[0, 1, 2], [1, 2, 2]], max_distance=3 → 2
From town 1 both other towns are within 3 km, while towns 0 and 2 each reach only town 1. Towns 0 and 2 tie, so the larger number, 2, wins.
n=4, roads=[[0, 1, 1], [1, 2, 1], [2, 3, 5]], max_distance=2 → 3
Town 3 is reachable only over a road of length 5, so no town lies within 2 km of it.
n=3, roads=[[0, 1, 2], [1, 2, 2]], max_distance=3
2
Run checks the first 3 tests in your browser. Submit checks all 62 tests on the server, hidden ones included.