L. Rikka with Grid Graphs

Codeforces
IDCF10201L
Time8000ms
Memory1024MB
Difficulty
English · Original
Formal · Original
A two-dimensional grid graph, also known as a square grid graph, is an undirected graph with $n m$ vertices corresponding all nodes in a $n times m$ grid. An edge here is an abstract description for a matchstick of length one in the grid connecting two adjacent nodes. Now, Rikka gives you a $n times m$ grid graph made with no more than $(2 n m -n -m)$ edges. She wants you to calculate the number of different orientations for the undirected graph such that the oriented graph is a directed graph with no directed cycles. In this problem, an orientation of an undirected graph is an assignment of a direction to each edge, turning the initial graph into a directed graph. The input contains several test cases, and the first line contains a single integer $T$ ($1 <= T <= 60$), the number of test cases. For each test case, the first line contains two integers $n$ and $m$ ($1 <= n, m <= 6$), the number of vertices in one column and one row of the grid graph respectively. Then $(2 n -1)$ lines follow, each of which has at most $(2 m -1)$ characters, describing the grid graph. The odd lines of them contain grid vertices, represented by separated plus signs ('_+_'), and zero or more horizontal edges, while the even lines of them contain zero or more vertical edges. Specifically, all possible vertices are represented in the input. Each horizontal edge connecting neighbouring vertices is represented by a single minus sign ('_-_'), while each vertical edge is represented by a single vertical bar ('_|_'). The edge characters will be placed exactly between the corresponding vertices. All other characters will be space characters. Note that if any input line could contain trailing whitespace, that whitespace will be omitted. For each test case, output a single line with a single integer, the number of valid orientations for the given grid graph. ## Input The input contains several test cases, and the first line contains a single integer $T$ ($1 <= T <= 60$), the number of test cases.For each test case, the first line contains two integers $n$ and $m$ ($1 <= n, m <= 6$), the number of vertices in one column and one row of the grid graph respectively.Then $(2 n -1)$ lines follow, each of which has at most $(2 m -1)$ characters, describing the grid graph. The odd lines of them contain grid vertices, represented by separated plus signs ('_+_'), and zero or more horizontal edges, while the even lines of them contain zero or more vertical edges. Specifically, all possible vertices are represented in the input. Each horizontal edge connecting neighbouring vertices is represented by a single minus sign ('_-_'), while each vertical edge is represented by a single vertical bar ('_|_'). The edge characters will be placed exactly between the corresponding vertices. All other characters will be space characters.Note that if any input line could contain trailing whitespace, that whitespace will be omitted. ## Output For each test case, output a single line with a single integer, the number of valid orientations for the given grid graph. [samples]
**Definitions** Let $ G = (V, E) $ be an undirected grid graph with $ V = [n] \times [m] $, where $ n, m \in \mathbb{Z}^+ $, and $ |E| \leq 2nm - n - m $. Each edge in $ E $ is either horizontal (connecting $ (i,j) $ to $ (i,j+1) $) or vertical (connecting $ (i,j) $ to $ (i+1,j) $). **Constraints** 1. $ 1 \leq T \leq 60 $ 2. For each test case: $ 1 \leq n, m \leq 6 $ 3. The graph is a subgraph of the full $ n \times m $ grid graph, with edges explicitly given via a text representation. 4. The graph is connected or disconnected, but contains only existing edges as described. **Objective** Count the number of orientations $ \vec{G} $ of $ G $ such that $ \vec{G} $ is a directed acyclic graph (DAG). That is, assign a direction to each undirected edge in $ E $ such that no directed cycles exist in the resulting digraph.
API Response (JSON)
{
  "problem": {
    "name": "L. Rikka with Grid Graphs",
    "description": {
      "content": "A two-dimensional grid graph, also known as a square grid graph, is an undirected graph with $n m$ vertices corresponding all nodes in a $n times m$ grid. An edge here is an abstract description for a",
      "description_type": "Markdown"
    },
    "platform": "Codeforces",
    "limit": {
      "time_limit": 8000,
      "memory_limit": 1048576
    },
    "difficulty": "None",
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "CF10201L"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "A two-dimensional grid graph, also known as a square grid graph, is an undirected graph with $n m$ vertices corresponding all nodes in a $n times m$ grid. An edge here is an abstract description for a...",
      "is_translate": false,
      "language": "English"
    },
    {
      "statement_type": "Markdown",
      "content": "**Definitions**  \nLet $ G = (V, E) $ be an undirected grid graph with $ V = [n] \\times [m] $, where $ n, m \\in \\mathbb{Z}^+ $, and $ |E| \\leq 2nm - n - m $.  \nEach edge in $ E $ is either horizontal (...",
      "is_translate": false,
      "language": "Formal"
    }
  ]
}
Full JSON Raw Segments