#P11356. [eJOI 2023] Opening Offices
[eJOI 2023] Opening Offices
Problem Description
Your company is going to build offices on an grid graph. As shown in the figure, the grid graph has horizontal and vertical edges, and all edge weights are .

During the day, all roads can be used. During the night, only edges are lit and can be used.
You like to patrol the offices. Every day, you start from one office, traverse each office exactly once through available edges in some order, and finally return to the starting point. You want to choose a subset of vertices on the grid graph such that the length of the shortest route needed for patrolling is the same during the day and during the night.
You need to compute, modulo , the number of possible under three different requirements:
- .
- .
- .
Input Format
The first line contains three integers , where indicates which version of the problem you need to compute.
Then follow lines, each containing a string of length .
- means that has an edge to .
- means that has an edge to .
It is guaranteed that the input forms a tree.
Output Format
Output one integer, the answer modulo .
2 3 2
022
031
12
2 3 3
022
031
10
2 3 1
022
031
25
Hint
[Sample Explanation]
As shown in the figure above.
The following are the valid choices when : , , , , , , , , , , , .
The following are the valid choices when : , , , , , , , , , .
The following are the valid choices when : , , .
[Constraints]
This problem uses bundled subtasks.
- Subtask 1 (4 pts): .
- Subtask 2 (5 pts): .
- Subtask 3 (9 pts): , .
- Subtask 4 (11 pts): .
- Subtask 5 (9 pts): , .
- Subtask 6 (13 pts): .
- Subtask 7 (14 pts): , .
- Subtask 8 (10 pts): , .
- Subtask 9 (9 pts): , .
- Subtask 10 (16 pts): .
For of the testdata, it is guaranteed that , , and $A_{i,j} \in \{\texttt{0}, \texttt{1}, \texttt{2}, \texttt{3}\}$.
Translated by ChatGPT 5