403861: GYM101343 C MRT Map
Description
Alaa and Duaa spent a long day in Universal Studios in Sentosa island, and now it's time to go back to home. The best way to get home is by using the train, starting from "HarbourFront" station and ending at "Serangoon" station.
Because the journey to home is long, Alaa and Duaa decided to invent a new game and play with it to spend time. In this game, they will use the train system map in Singapore (which called MRT map). The game goes as follow:
- Alaa will choose a station to start a journey from it.
- Duaa will choose a station to end the journey in it.
- Alaa and Duaa will start calculating the minimum cost to go from the starting station to the end station. And the winner is the one who can find the shortest distance from the starting station to the end station.
The cost to go from station u to station v, is the number of common letters in the names of the two station. For example, the cost to go from "HarbourFront" station to "Serangoon" station is 4, because there exist 4 common letters, which are 'a', 'n', 'o' and 'r'. Note that each letter will be count once only (e.g. the letter 'o' exist two times in "HarbourFront" and two times "Serangoon", but it will add only 1 to the cost).
The letters in the names are case insensitive. For example the cost to go from city with name "AbC" to city with name "aBc" is 3, because the three letters in both names are common regardless of the state of the letter (uppercase or lowercase).
Alaa and Duaa need your help to find the shortest distance from the starting station to the end station, to announce the winner's name. Can you?
InputThe first line contains two integers n and m (2 ≤ n ≤ 104) (n - 1 ≤ m ≤ min(105, )), where n is the number of stations in the map, and m is the number of links between the stations.
Then n lines follow, each line i contains the name of the ith station in the map. The name of each station is a non-empty string consisting of English letters only, and with length no more than 20.
Then m lines follow, each line contains two integers u and v (1 ≤ u, v ≤ n), which mean that there is a link between stations u and v. It is guaranteed that no link will connect a station with itself, and there is at most one link between any two stations.
You can use the given links only to move between stations.
The next line contains two integers s and e (1 ≤ s, e ≤ n), where s is the starting stating (which were chosen by Alaa), and e is the end station (which were chosen by Duaa). It is guaranteed that you can go from any station to any other station in the map.
OutputPrint the shortest distance from the starting station s to the end station e.
ExamplesInput6 5Output
Bishan
Marymount
Caldecott
BotanicGardens
LorongGhuan
Serangoon
1 2
2 3
3 4
1 5
5 6
4 6
19Input
13 13Output
BuonaVista
OneNorth
KentRidge
HawParVilla
PasirPanjang
LabradorPark
TelokBlangah
HarbourFront
Commonwealth
Queenstown
Redhill
TiongBahru
OutramPark
1 2
2 3
3 4
4 5
5 6
6 7
7 8
1 9
9 10
10 11
11 12
12 13
13 8
10 8
14