luogu#P3513. [POI2011] KON-Conspiracy

[POI2011] KON-Conspiracy

题目描述

Hostile Bitotia launched a sneak attack on Byteotia and occupied a significant part of its territory.

The King of Byteotia, Byteasar, intends to organise resistance movement in the occupied area.

Byteasar naturally started with selecting the people who will form the skeleton of the movement.

They are to be partitioned into two groups:

the conspirators who will operate directly in the occupied territory, and the support group that will operate inside free Byteotia.

There is however one issue - the partition has to satisfy the following conditions:

Every pair of people from the support group have to know each other - this will make the whole group cooperative and efficient.

The conspirators must not know each other.

None of the groups may be empty, i.e., there has to be at least one conspirator and at least one person in the support group.

Byteasar wonders how many ways there are of partitioning selected people into the two groups.

And most of all, whether such partition is possible at all.

As he has absolutely no idea how to approach this problem, he asks you for help.

输入格式

The first line of the standard input holds one integer nn (2n50002\le n\le 5000), denoting the number of people engaged in forming the resistance movement.

These people are numbered from 1 to nn (for the sake of conspiracy!).

The nn lines that follow describe who knows who in the group.

The ii-th of these lines describes the acquaintances of the person ii with a sequence of integers separated by single spaces.

The first of those numbers, kik_i (0kin10\le k_i\le n-1), denotes the number of acquaintances of the person ii.

Next in the line there are kik_i integers ai,1,ai,2,,ai,kia_{i,1},a_{i,2},\cdots,a_{i,k_i} - the numbers of ii's acquaintances.The numbers ai,ja_{i,j} are given in increasing order and satisfy 1ai,jn1\le a_{i,j}\le n,ai,jia_{i,j}\ne i. You may assume that if xx occurs in the sequence aia_i (i.e., among ii's acquaintances), then also ii occurs in the sequence axa_x(i.e., among xx's acquaintances).

输出格式

In the first and only line of the standard output your program should print out one integer:

the number of ways to partition selected people into the conspirators and the support group.

If there is no partition satisfying aforementioned conditions, then 0 is obviously the right answer.

题目大意

描述

Byteotia的领土被占领了,国王Byteasar正在打算组织秘密抵抗运动。国王需要选一些人来进行这场运动,而这些人被分为两部分:一部分成为同谋者活动在被占领区域,另一部分是后勤组织在未被占领的领土上运转。但是这里出现了一个问题:

  1. 后勤组织里的任意两人都必须是熟人,以促进合作和提高工作效率。
  2. 同谋者的团体中任意两人都不能是熟人。
  3. 每一部分都至少要有一个人。国王想知道有多少种分配方案满足以上条件,当然也有可能不存在合理方案。

现在国王将这个问题交由你来解决!

输入

第一行一个整数n(2<=n<=5000)表示有n个人参与该抵抗运动,标号为1..n。

之后有n行,第i行的第一个数ki(0<=ki<=n-1)表示i认识ki个人,随后的ki个数表示i的熟人。

输入满足如果i是x的熟人,x会在i的序列中出现同时i也会出现在x的熟人序列中。

输出

符合条件的方案总数。

4
2 2 3
2 1 3
3 1 2 4
1 3
3