#P17164. [CEOI 2026] DFS
[CEOI 2026] DFS
Problem Description
You might already be familiar with the famous DFS (depth-first search) algorithm for traversing a graph. In this problem, we will only consider connected undirected simple graphs (without loops and parallel edges) with vertices numbered , and the DFS algorithm will output depths and vertices as follows:
DFS(d, v):
output d/v
mark vertex v as visited
W = the list of neighbors of v ordered by increasing numbers
for each w in W:
if vertex w has not yet been visited:
DFS(d + 1, w)
Write a program that outputs the number of different graphs for which the call DFS(, ) produces the same printout as the one given on the input. For example, the output
is produced by calling DFS(, ) on either of the following two connected undirected simple -vertex graphs:
:::align{center}
:::
Input Format
The input is the output of the call DFS(, ) on an unknown -vertex connected undirected simple graph. The input thus consists of lines in the format , with the first line being .
Output Format
Print the number of different graphs with the required property. Because this number can be very large, output the result modulo .
0/2
1/0
2/1
2
Hint
Constraints
Subtasks
- Subtask ( points): .
- Subtask ( points): .
- Subtask ( points): .
- Subtask ( points): For each , the -th input line is .
- Subtask ( points): For each , the -th input line is for some .
- Subtask ( points): No additional constraints.