Problem Statement
There is a country with n cities, numbered 0 through n-1.
City 0 is the capital.
The road network in the country forms an undirected connected graph.
In other words:
Some pairs of cities are connected by bidirectional roads.
For every city there is at least one sequence of consecutive roads that leads from the city to the capital.
(Whenever two roads need to cross outside of a city, the crossing is done using a bridge, so there are no intersections outside of the cities.)
You are given a String[] linked that describes the road network.
For each i and j, linked[i][j] is 'Y' if the cities i and j are already connected by a direct road, and it is 'N' otherwise.
The distance between two cities is the smallest number of roads one needs to travel to get from one city to the other.
The people living outside of the capital are usually unhappy about their distance from the capital.
You are also given a int[] want with n elements.
For each i, want[i] is the desired distance between city i and the capital (city 0).
Fox Ciel is in charge of building new roads.
Each new road must again be bidirectional and connect two cities.
Once the new roads are built, the citizens will evaluate how unhappy they are with the resulting road network:
For each i: Let real[i] be the new distance between city i and the capital.
Then the people in city i increase the unhappiness of the country by (want[i] - real[i])^2.
Return the minimal total unhappiness Ciel can achieve by building some (possibly zero) new roads.