1. An electric car is a car that does not run on gas or other fossil fuel. It is powered by a battery that needs to be recharged regularly.
You want to travel from city A to city B in an electric car. There are charging stations in all cities and you are given the following data.
1. Map of the country in the form of cities and roads connecting them.
2. length of the roads connecting the cities.
3. All roads support two way traffic
Assuming that K units of battery charge lets you travel across a distance of K units. What is the minimum battery capacity that you need to reach city B, without getting stranded between any two cities while travelling.
Note
1. There will be N cities in the country and City A is the 1st City and City B is the Nth city, these cities will be connected by M roads
2. It is guaranteed that city B can be reached from city A using some roads.
Assumption
N = 3
M = 3
Roads = [{1, 2, 5}, {2, 3, 5}, {1, 3, 9}]
The Map of the country is
If not possible then return -1;

Comments
Post a Comment