For every split of N countries into aggressors and peaceful, decide the winner of the tank game under optimal play, then count Mirko's and Slavko's wins.
Hard8Game theoryCombinatoricsSimulationNo attempts yetTime limit5sMemory limit128 MBMirko and Slavko have played Risk a thousand times, so they are inventing a new game called Aggressor that uses the same board, a map. The board has N countries numbered 1 to N, and it is known which pairs of countries are neighbors. Two countries can be neighbors even when they do not share a physical border.
Before the game starts, the two players put a number of tanks in every country and declare some of the countries aggressors. The remaining countries are peaceful. Mirko and Slavko then alternate, one move each. A player who cannot move loses the game. Mirko moves first.
On his turn a player picks one of two kinds of moves.
Attack:
Help:
Countries belong to neither player. On his turn a player may pick any two neighboring countries as long as the move is allowed.
The board has N countries, so there are 2N ways to split them into aggressors and peaceful countries. Mirko and Slavko play one game for each way. Count how many of those 2N games Mirko wins and how many Slavko wins when both play optimally.
For some splits neither player can force a win. If no country is an aggressor, for example, no tank can ever be destroyed, so the game never ends.
The first line contains the integer N (2≤N≤40), the number of countries.
The second line contains the number of tanks in each country at the start of the game, from country 1 to country N. Each of those N numbers is a positive integer smaller than 40000.
The third line contains the integer M (1≤M≤780), the number of neighboring pairs.
Each of the next M lines contains the numbers of two countries that are neighbors. No pair appears more than once in this list.
In the first line, print the total number of games Mirko wins.
In the second line, print the total number of games Slavko wins.
Take two countries that are neighbors, each holding 100 tanks. Of the four splits, Mirko wins two and Slavko wins one.