#P4336. [SHOI2016] 黑暗前的幻想乡

[SHOI2016] 黑暗前的幻想乡

Description

After taking office, Yuuka’s first measure is to build Gensokyo’s highways. There are nn cities in Gensokyo, and initially there are no roads. Yuuka promised voters to cut taxes, so she plans to build only n1n - 1 roads to connect all these cities. There are exactly n1n - 1 construction companies, and each company wants to gain some benefits during road construction. Although these companies did not give Yuuka money before the election, she still intends to maintain good relations with them, since she is counting on them to help her build the wall. So she plans to have each construction company be responsible for exactly one road.

Each construction company has told Yuuka between which pairs of cities it is capable of building a road. Yuuka will choose n1n - 1 edges that can connect all cities in Gensokyo, then assign each edge to a construction company that can build it, with each company building exactly one edge.

Yuuka now wants to know how many possible schemes there are in total. Two schemes are different if and only if either the set of edges to be built is different, or the assignment of companies to edges is different.

Input Format

The first line contains an integer nn, the number of cities.

Lines 22 through nn: line i+1i + 1 describes the list of roads that the ii-th construction company can build. It starts with a non-negative integer mim_i, the number of roads it can build; then follow mim_i pairs of integers u,vu, v, each pair denoting the endpoints of an edge. Within a company’s list, there are no duplicate edges and no self-loops.

Output Format

Output a single integer on one line: the number of all possible schemes modulo 109+710^9+7.

4
2 3 2 4 2
5 2 1 3 1 3 2 4 1 4 3
4 2 1 3 2 4 1 4 2
17

Hint

Constraints

  • For 20%20\% of the test points, n5n \le 5.
  • For 50%50\% of the test points, n8n \le 8.
  • For 60%60\% of the test points, n10n \le 10.
  • For 100%100\% of the test points, 2n172 \leq n \le 17, 0min(n1)20 \leq m_i \leq \frac{n(n - 1)}{2}, 1u,vn1 \leq u, v \leq n.

Translated by ChatGPT 5