当前你的浏览器版本过低,网站已在兼容模式下运行,兼容模式仅提供最小功能支持,网站样式可能显示不正常。
请尽快升级浏览器以体验网站在线编辑、在线运行等功能。

建议使用的浏览器:

谷歌Chrome 火狐Firefox Opera浏览器 微软Edge浏览器 QQ浏览器 360浏览器 傲游浏览器

6795:Little W and Contest

题目描述
There are $n$ members in our ACM club. Little W wants to select three persons from our club to form a new team taking part in provincial ACM contests, as it is known by all of us that any ACM contest requires a normal team to have three members.

Little W has divided our club members into two role groups. The first group contains only readers who dedicate themselves to reading problems during contests, though sometimes they may also prepare drinking and food for the team. For the sake of measurement, we define the power of a reader as $1$. The second part contains only coders who code and test programs all the time, and similarly, we define the power of a coder as $2$.

Little W thinks it will be a tremendous disaster when a team has two readers because in that case, the total power of this team is less than $5$ and thus it has a high risk to fail the contest. To avoid that, Little W thinks a new team must have at least two coders.

Additionally, Little W defines the relationship between club members with transitivity. That is, for every three members $A$, $B$, and $C$, if $A$ is familiar with $B$, and $B$ is familiar with $C$, then $A$ will be familiar with $C$ through $B$ instantly. Based on the definition, it is forbidden for the team to have any two members familiar with each other.

At first, no member of our club is familiar with any other, and then Little W will repeatedly make an introduction between two members who are currently strangers to each other until each member is familiar with all the others. During this process, there will be exactly $(n - 1)$ introductions.

Now, for $i = 1, 2, \ldots, n$, Little W wants you to count the combinations of three club members that can form a new team after the first $(i - 1)$ introductions have been made. However, the numbers of combinations may be quite gigantic, so you just need to report each number in modulo $(10^9 + 7)$.
输入解释
There are several test cases.

The first line contains an integer $T$ ($1 \leq T \leq 10$), denoting the number of test cases. Then follow all the test cases.

For each test case, the first line contains an integer $n$ $(1 \leq n \leq 10^5)$, denoting the number of members in this club.

The second line contains $n$ integers consisting of only $1$ and $2$, where the $i$-th integer represents the power of the $i$-th member.

The next $(n - 1)$ lines describe all introductions in chronological order of occurrence, where each line contains two integers $u$ and $v$ $(1 \leq u, v \leq n, u \neq v)$, representing an introduction between the $u$-th member and the $v$-th member, who are currently strangers to each other.

It is guaranteed that the sum of $n$ is no larger than $10^6$.
输出解释
For each test case, output $n$ lines, where the $i$-th line contains an integer, denoting the number of combinations of three club members, in modulo $(10^9 + 7)$, that can form a new team after the first $(i - 1)$ introductions have been made.
输入样例
1
5
2 2 2 1 1
4 5
1 4
2 1
3 2
输出样例
7
7
3
0
0
来自杭电HDUOJ的附加信息
Recommend liuyiding

该题目是Virtual Judge题目,来自 杭电HDUOJ

源链接: HDU-6795

最后修改于 2020-10-25T23:34:26+00:00 由爬虫自动更新

共提交 0

通过率 --%
时间上限 内存上限
2000/2000MS(Java/Others) 524288/524288K(Java/Others)