Here is the question:
exmaple:
5
12 34 10 7 8
3
1 2
2 3
3 1
Output:
56
groups formed are [1,2,3][4][5] max