The Computer Game
Time limit1sMemory limit128 MB
Given a diamond-shaped lattice grid with some cells blocked, count all nonempty subsets of free cells that form a single connected (4-adjacency) region.
- Level
Medium6 of 10
- Topics
- Brute force, Graph, Bit manipulation, DFS
- Solved
- No attempts yet
Problem
John and Brus are playing a strategy game on a computer. The game takes place on a flat map. First Brus deploys his army; then John must choose strategic points for his own army according to the following rules:
- Each strategic point must be a lattice point (a point with integer coordinates) such that .
- John may choose any positive number of strategic points.
- All chosen strategic points must be distinct.
- Each strategic point must be free, i.e. not occupied by Brus's army.
- Every pair of chosen strategic points must be connected, where the connection may pass only through other chosen strategic points.
Two distinct lattice points and are adjacent (directly connected) when . Connection is transitive through chosen points: if chosen points and are adjacent and and are adjacent, then and are connected. In other words, the set of chosen points must form a single connected region under this adjacency.
Count the number of ways for John to choose his strategic points.
Input
The first line contains a single integer , the number of test cases. Each test case begins with a line containing two integers and : is the value used in the first rule, and is the number of lattice points already occupied by Brus's army. Each of the next lines contains two integers and , the coordinates of one occupied point.
Constraints: , , , , and all are distinct.
Output
For each test case, print a single line containing the number of ways for John to choose his strategic points.