Training Material

## Advanced Graph Algorithms→ATM Robbery (APIO 2009)

The city of Siruseri has only one way roads. Roads meet at intersections and at every intersection, mandated by law, there is an ATM of the Bank of Siruseri. Strangely, the pubs in Siruseri are also located only at intersections, though not every intersection hosts a pub.

Banditji plans to carry out the largest ATM robbery in the history of Siruseri. He will start from the city centre and drive around, robbing all the ATMs that he passes by, before ending the day at one of the city's pubs to celebrate his achievement.

Using his well-honed hacking skills, Banditji has precise information about the amount of cash available at every ATM. He would like you to help him determine the total amount that he can rob by starting at the city centre and ending at one of the city's pubs. He can go through the same intersection or road any number of times. However, there is no money to be picked up at an ATM after the first visit.

For instance, suppose the city had 6 intersections connected by roads as indicated below:

```
10         12         8          1
-->[1] ------> [2] ---> [[3]] --> [[5]]
^           /\                  ^
\         /  \                /
-[[4]]<-     --->[[6]]------
16              5
```

The city centre is at intersection 1, marked by an incoming → and the intersections where pubs are found are marked by a double bracket. The amount of cash available at the respective ATMs is written by the side of each intersection. In this case, Banditji can rob a total of 47 by following the route 1→2→4→1→2→3→5.

Solution