You are the commander of a group of soldiers on a battlefield. There are several forts on that battlefield, and you and your soldiers are currently at fort 0. Your task is to send a soldier to each of the other forts to deliver some secret prototypes.
Your mission is considered complete when there is exactly one solider at each of the other forts. You want to complete the mission as soon as possible, but you also want to maintain your high popularity among your soldiers. You have noticed that allowing soldiers to sleep a couple of hours before beginning their missions will make you more popular with them. Specifically, if you let one soldier sleep for X hours before beginning his mission, you will gain X popularity points.
You are given a String[] roads, where the j-th character of the i-th element is '-' if no road exists between forts i and j, or a digit between '0' and '9' representing the number of hours it would take a soldier to travel between forts i and j. Return the maximum total number of popularity points you can gain while still completing the mission as quickly as possible. Return -1 if it is impossible to complete the mission. |