Problem B
Excavator Expedition

Little Nanouk is obsessed with excavators. In fact, he is so obsessed with them that he will throw a tantrum if he doesn’t see too many during a road trip.
This poses a problem for his mother Amka, who wants to bring him to his grandparents today. To make the drive to his grandparents as smooth as possible, she has plotted out all the construction sites they could see on their way, along with the “boring” sites (according to Nanouk). Of course, Amka also wants to make some progress for each place they drive to. For that reason, the map she has plotted out is a directed acyclic graph.
Could you help Amka find the route to their grandparents which makes Nanouk as happy as possible?
Input
First, a single line with two integers
Then follow
The location
Output
Output the happiness of Nanouk if Amka drives the route which maximises Nanouk’s happiness. Nanouk’s happiness is defined as the number of construction sites visited, minus the number of boring sites (except for Amka’s and Nanouk’s grandparents’ house).
Limits
-
-
-
-
For all
, {‘.’, ‘X’} -
For
, ‘.’ -
There is always a path from Amka’s house to Nanouk’s grandparents.
-
There are no cycles in the graph.
Sample Input 1 | Sample Output 1 |
---|---|
13 15 .X...X.X...X. 0 1 0 2 1 3 2 4 3 5 4 5 5 6 5 7 5 8 6 12 7 9 8 10 9 11 10 11 11 12 |
2 |