{"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 matchstick of length one in the grid connecting two adjacent nodes.\n\nNow, 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.\n\nIn 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.\n\nThe input contains several test cases, and the first line contains a single integer $T$ ($1 <= T <= 60$), the number of test cases.\n\nFor 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.\n\nThen $(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.\n\nNote that if any input line could contain trailing whitespace, that whitespace will be omitted.\n\nFor each test case, output a single line with a single integer, the number of valid orientations for the given grid graph.\n\n## Input\n\nThe 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.\n\n## Output\n\nFor each test case, output a single line with a single integer, the number of valid orientations for the given grid graph.\n\n[samples]","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 (connecting $ (i,j) $ to $ (i,j+1) $) or vertical (connecting $ (i,j) $ to $ (i+1,j) $).\n\n**Constraints**  \n1. $ 1 \\leq T \\leq 60 $  \n2. For each test case: $ 1 \\leq n, m \\leq 6 $  \n3. The graph is a subgraph of the full $ n \\times m $ grid graph, with edges explicitly given via a text representation.  \n4. The graph is connected or disconnected, but contains only existing edges as described.  \n\n**Objective**  \nCount the number of orientations $ \\vec{G} $ of $ G $ such that $ \\vec{G} $ is a directed acyclic graph (DAG).  \nThat is, assign a direction to each undirected edge in $ E $ such that no directed cycles exist in the resulting digraph.","is_translate":false,"language":"Formal"}],"meta":{"iden":"CF10201L","tags":[],"sample_group":[],"created_at":"2026-03-03 11:00:39"}}