Problem of the day
1. If multiple such cities exist, you have to find the city with the greatest number.
2. The distance of a path connecting two cities, ‘U’ and ‘V’, is the sum of the weight of the edges along that path.
3. The distance between two cities is the minimum of all possible path distances.
The first line contains an integer ‘T’, which denotes the number of test cases to be run. Then, the T test cases follow.
The first line of each test case contains three positive integers, ‘N’, ‘M’, and ‘distanceThreshold’, as described in the problem statement.
The next ‘M’ lines of each test case contain three integers, ‘U’, ‘V’, and ‘W’ each, representing each edge of the graph.
The edge U V W represents an edge between vertices ‘U’ and ‘V’, having weight ‘W’.
The ‘edges’ will be passed to the function as an array of arrays. Each array will contain three integers, ‘U’, ‘V’, and ‘W’ in that order.
For each test case, print a single line containing a single integer denoting the required ‘city’ number, as described in the problem statement.
The output for each test case will be printed in a separate line.
You do not need to print anything. It has already been taken care of. Just implement the given function.
1 <= T <= 10
2 <= N <= 100
1 <= M <= (N * (N - 1)) / 2
0 <= U, V < N
1 <= W, distanceThreshold <= 100
Where ‘T’ denotes the number of test cases, ‘N’ represents the number of cities, and ‘M’ denotes the number of edges.
‘U’, ‘V’, and ‘W’ denote the edge between city ‘U’ and ‘W’ having weight ‘W’.
Time limit: 1 sec.
1
5 5 3
0 1 1
1 2 1
2 3 3
3 4 1
0 3 3
4
The cities reachable to each city at a ‘distanceThreshold’ = 3 are as follows:
City 0 -> {City 1, City 2, City 3}
City 1 -> {City 0, City 2}
City 2 -> {City 0, City 1, CIty 3}
City 3 -> {City 0, City 2, City 3}
City 4 -> {City 3}
The city with the smallest number of neighbors at a ‘distanceThreshold’ = 3 is city 4 which has only 1 neighboring city.
1
3 3 4
0 1 2
1 2 2
2 0 1
2
The cities reachable to each city at a ‘distanceThreshold’ = 4 are as follows:
City 0 -> {City 1, City 2}
City 1 -> {City 0, City 2}
City 2 -> {City 0, City 1}
All three cities have 3 neighboring cities, So the answer must be the city with the greatest number that is city 2.