Woburn Challenge 2018-19 Finals Round - Senior Division
With principal photography on the cows' and monkeys' project having concluded, it won't be long now before post-production wraps up and the film can be shown to the public! In preparation for the initial run of screenings, the Head Monkey and Bo Vine are taking it upon themselves to personally put up movie posters at movie theatres all across the land of Ontario.
There are cities in Ontario, numbered from to . City either has a movie theatre (indicated by ) or doesn't (), and at least one city in Ontario has a theatre.
There are also highways, the -th of which allows one to travel in either direction between two different cities and . It's possible to travel from any city to any other city by following a sequence of highways.
The Head Monkey will begin in city , while Bo Vine will begin in a different city . Neither of their starting cities have movie theatres . Each hour, the Head Monkey and/or Bo Vine may each travel along a highway from their current city to an adjacent one. They are allowed to both be present in the same city as one another. Whenever either of them visits a city with a movie theatre, they may put up a poster at it, which requires no additional time.
Between the two of them, the Head Monkey and Bo Vine would like to put up a poster at every movie theatre in Ontario. In other words, for each city such that , at least one of the two must visit it at some point. Furthermore, the Head Monkey and Bo Vine would each like to end up back at their original cities of and , respectively. Time is of the essence when it comes to getting the word out about their film, so help them determine the minimum amount of time required to complete this task!
Subtasks
In test cases worth of the points, , and each city has at
most two highways directly adjacent to it.
In test cases worth another of the points, .
Input Specification
The first line of input consists of three space-separated integers, ,
, and .
The next line consists of characters, .
lines follow, each of which consists of two space-separated
integers, and , for .
Output Specification
Output a single integer, the minimum number of hours required for the Head Monkey and Bo Vine to visit all of the theatres and each return to their original city.
Sample Input 1
5 2 4
00101
1 2
2 3
3 4
4 5
Sample Output 1
2
Sample Input 2
8 1 6
00110011
1 2
2 3
2 4
4 5
1 6
6 7
7 8
Sample Output 2
6
Sample Input 3
5 1 2
00101
5 4
3 1
1 2
4 1
Sample Output 3
4
Sample Explanation
In the first case, one possible optimal pair of routes is as follows:
- Head Monkey:
- Bo Vine:
In the second case, one possible optimal pair of routes is as follows:
- Head Monkey:
- Bo Vine:
In the third case, one possible optimal pair of routes is as follows:
- Head Monkey:
- Bo Vine:
Comments