Conspiracy
Time limit3sMemory limit128 MB
Given a mutual acquaintance graph on n people, count the ways to split all n people into a nonempty independent set (conspirators) and a nonempty clique (support) that together cover everyone.
- Level
Medium7 of 10
- Topics
- Graph, Combinatorics, Math, Implementation
- Solved
- No attempts yet
Problem
Hostile Bitotia has attacked Byteotia and occupied a large part of its territory. King Byteasar of Byteotia wants to organize a resistance movement in the occupied area, so he begins by choosing the people who will form its core. These chosen people must be split into two groups:
- the conspirators, who will operate directly in the occupied territory, and
- the support group, who will operate inside free Byteotia.
The split has to satisfy all of the following rules:
- Every two people in the support group know each other, so the group can cooperate efficiently.
- No two conspirators know each other.
- Neither group is empty: there is at least one conspirator and at least one member of the support group.
Byteasar wants to know how many ways there are to split the chosen people into these two groups, and above all whether any valid split exists at all. Help him find this number.
Input
The first line contains one integer (), the number of people involved. The people are numbered from to .
Each of the next lines describes the acquaintances of one person. The -th of these lines begins with an integer (), the number of people that person knows, followed by integers given in increasing order (, ), the numbers of those acquaintances.
Acquaintance is mutual: if person appears among person 's acquaintances, then person appears among person 's acquaintances.
Output
Print one integer: the number of ways to split the chosen people into the conspirators and the support group so that all the rules above hold. If no valid split exists, print .
Hint

In the example above there are three valid splits. The group of conspirators can be persons and , persons and , or person alone.