Farmland
Time limit1sMemory limit128 MB
Given a planar graph of farming regions, count the proper regions bounded by a simple cycle with no interior vertices or edges and exactly k boundary edges.
- Level
Hard8 of 10
- Topics
- Graph, Geometry, Implementation, DFS
- Solved
- No attempts yet
Problem
You are given the farmland map of a country. The whole farmland is divided into a set of disjoint farming regions, and each farmer owns exactly one region. There is a boundary fence between two neighboring regions. The map can be represented as a plane graph .
There are two kinds of edges: a boundary edge, which lies between two neighboring regions, and a non-boundary edge, which sticks into the interior of a region.
A proper farming region is a closed region bounded by a single simple cycle that contains no vertex or edge in its interior. For example, if a quadrilateral has another vertex inside it, that quadrilateral is not a proper region. A region whose bounding cycle is not simple (it repeats a vertex or an edge) is not proper either. A degenerate region with no interior area (for example, one made of only two vertices) is also not proper.
Assume the following about :
- The graph is simple and connected: there are no self-loops and no parallel edges.
- The outer (unbounded) face of is never counted.
- There is at least one proper farming region.
- All vertex positions are distinct.
- No two edges cross, so is a plane graph.
The size of a proper farming region is the number of boundary edges around it. For example, a quadrilateral region bounded by four edges has size .
Given an integer , count how many proper farming regions have size exactly . If there is no such region, print .
Input
The first line contains the number of test cases ().
Then test cases follow. The first line of each test case contains the number of vertices ().
Each of the next lines describes one vertex in the form:
i xi yi di a1 a2 ... adi
Here is the vertex number, is the coordinate of vertex , is the degree of vertex , and are the vertices adjacent to .
The last line of each test case contains , the size of the proper regions you must count.
All vertices lie on grid points of a lattice.
Output
For each test case, print on its own line the number of proper farming regions whose size is exactly . In other words, print non-negative integers.