QOJ.ac

QOJ

Time Limit: 1 s Memory Limit: 1024 MB Total points: 100

#15030. 随机二分图

统计

某人在玩一个非常神奇的游戏。这个游戏中有一个左右各 $n$ 个点的二分图,图中的边会按照一定的规律随机出现。

为了描述这些规律,某人将这些边分到若干个组中。每条边或者不属于任何组 (这样的边一定不会出现),或者只属于一个组。

有且仅有以下三类边的分组:

  1. 这类组每组只有一条边,该条边恰好有 $50\%$ 的概率出现。
  2. 这类组每组恰好有两条边,这两条边有 $50\%$ 的概率同时出现,有 $50\%$ 的概率同时不出现。
  3. 这类组每组恰好有两条边,这两条边恰好出现一条,各有 $50\%$ 的概率出现。

组和组之间边的出现都是完全独立的。

某人现在知道了边的分组和组的种类,想要知道完美匹配数量的期望是多少。你能帮助她解决这个问题吗?

定义解释

如果你对完美匹配和期望的定义很熟悉,那么你可以跳过本段。

对于一个左右各 $n$ 个点的二分图,它的一个完美匹配是指 $n$ 条没有公共点的边构成的匹配。

两个完美匹配不同,当且仅当它们至少含有一条不同的边。一个二分图完美匹配的数量定义为这张图能找到的两两不同的完美匹配的数量。

在题目的图中,边都是随机出现的,因此这个图中完美匹配的数量是一个随机变量。一个(离散型)随机变量 $X$ 的期望定义为以概率为权,$X$ 所有可能取值的加权平均数,即 $$ \sum_{x \in V(X)}P[X=x]\cdot x $$ 其中 $V(X)$ 表示 $X$ 所有可能的取值集合,$P[X=x]$ 表示 $X$ 取值为 $x$ 的概率。

输入格式

从标准输入读入数据。

第一行两个数 $n$ 和 $m$,表示图左右点数的数量和边的组的个数。我们用 $(a,b)$ (其中 $1 \le a,b \le n$)表示一条左端点为二分图左侧第 $a$ 个点,右端点为二分图右侧第 $b$ 个点的边。

接下来 $m$ 行,每行描述一个组。开头第一个数 $t$ 表示组的种类,$t=0$ 表示是一条边的组,$t=1$ 表示是两条边的组中的第一种,$t=2$ 表示是两条边的组中的第二种。如果 $t=0$, 接下来两个数 $a_1,b_1$ 表示组内的第一条边;否则,接下来四个数 $a_1,b_1,a_2,b_2$, 表示该组内的两条边分别为 $(a_1,b_1)$ 和 $(a_2,b_2)$。保证每条边至多出现一次。

输出格式

输出到标准输出。

假设期望的完美匹配数量是$E$。输出一行表示 $$ (2^{n} E) \bmod (10^9 + 7) $$ 可以看出上式一定是一个整数。

样例

输入

2 2
1 2 1 2 2
2 1 2 1 1

输出

2

样例

输入

3 5
1 1 2 3 3
1 3 2 2 2
1 1 1 1 3
1 2 1 3 1
0 2 3

输出

7

样例3

见下载目录下的 ex_3.inex_3.ans

数据规模和约定

对于 $5\%$ 的数据 $n \le 5$ 。

对于另 $5\%$ 的数据 $n \le 8$ 。

对于另 $10\%$ 的数据 $n \le 10$ 。

对于另 $15\%$ 的数据,只有$t = 0$ 的情况。

对于另 $5\%$ 的数据,只有$t = 0$ 的情况,且$m = n^2$,也就是该图为一个完全图。

对于另 $20\%$ 的数据,只有 $t =0$ 或者 $t=1$ 的情况。

对于另 $20\%$ 的数据,只有 $t =0$ 或者 $t=2$ 的情况。

对于 $100\%$ 的数据,$n \le 15$。

About Issues

We understand that our problem archive is not perfect. If you find any issues with the problem, including the statement, scoring configuration, time/memory limits, test cases, etc.

You may use this form to submit an issue regarding the problem. A problem moderator will review your issue and proceed it properly.

STOP! Before you submit an issue, please READ the following guidelines:

  1. This is not a place to publish a discussion, editorial, or requests to debug your code. Your issue will only be visible by you and problem moderators. Other users will not be able to view or reply your issues.
  2. Do not submit duplicated issues. If you have already submitted one, please wait for an moderator to review it. Submitting multiple issues will not speed up the review process and might cause your account to be banned.
  3. Issues must be filed in English or Chinese only.
  4. Be sure your issue is related to this problem. If you need to submit an issue regarding another problem, contest, category, etc., you should submit it to the corresponding page.

Active Issues 0

No issues in this category.

Closed/Resolved Issues 0

No issues in this category.