##### ###### ##### ### # # ### # # ###### ## ## ## ## ## ## ## # # # # # ## ##### #### ##### # # # # # # # #### ## # ## ## ## ## # # # # # ## ## # ###### ## ### # ### # ######
##### ###### ##### ### # # ### # # ###### ## ## ## ## ## ## ## # # # # # ## ##### #### ##### # # # # # # # #### ## # ## ## ## ## # # # # # ## ## # ###### ## ### # ### # ######
##### ###### ##### ### # # ### # # ###### ## ## ## ## ## ## ## # # # # # ## ##### #### ##### # # # # # # # #### ## # ## ## ## ## # # # # # ## ## # ###### ## ### # ### # ######
3
3 3 1 2 2 3 1 3
3 2 1 3 2 3
7 10 1 2 1 3 2 3 1 4 2 4 1 5 2 5 1 6 2 6 1 7
3
0
31

Consider a connected undirected graph with vertices labeled and edges.
For each vertex, fix an ordering of its adjacency list (i.e., an order in which its neighbors will be considered).
Once these adjacency orders are fixed, running the standard depth-first search (DFS) starting from vertex becomes fully deterministic: whenever DFS is at a vertex, it scans its neighbors in the prescribed order and recursively visits the first unvisited neighbor it encounters, continuing until all reachable vertices are processed.
The DFS order of the graph (under the chosen adjacency orders) is defined as the sequence of vertices in the order they are first discovered by this DFS.
We call the graph nice if there exists a choice of adjacency-list orderings for all vertices such that the DFS order is exactly .
You are given a connected graph with vertices and edges. Count the number of subsets of edges whose removal makes the remaining graph nice.
Output the answer modulo .
Triangle with edges , , .
For DFS order : vertex must connect to (so edge is required), and vertex must connect to or (so at least one of or must remain).
Valid subsets: , , all three.
Answer: 3.
Edges , only.
Vertex has no edge to vertex , so there is no way to achieve DFS order .
Answer: 0.