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

建议使用的浏览器:

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

5739:Fantasia

题目描述
Professor Zhang has an undirected graph $G$ with $n$ vertices and $m$ edges. Each vertex is attached with a weight $w_i$. Let $G_i$ be the graph after deleting the $i$-th vertex from graph $G$. Professor Zhang wants to find the weight of $G_1, G_2, ..., G_n$.

The weight of a graph $G$ is defined as follows:

1. If $G$ is connected, then the weight of $G$ is the product of the weight of each vertex in $G$.
2. Otherwise, the weight of $G$ is the sum of the weight of all the connected components of $G$.

A connected component of an undirected graph $G$ is a subgraph in which any two vertices are connected to each other by paths, and which is connected to no additional vertices in $G$.
输入解释
There are multiple test cases. The first line of input contains an integer $T$, indicating the number of test cases. For each test case:

The first line contains two integers $n$ and $m$ $(2 \le n \le 10^5, 1 \le m \le 2 \times 10^5)$ -- the number of vertices and the number of edges.

The second line contains $n$ integers $w_1, w_2, ..., w_n$ $(1 \le w_i \le 10^9)$, denoting the weight of each vertex.

In the next m lines, each contains two integers $x_i$ and $y_i$ $(1 \le x_i, y_i \le n, x_i \ne y_i)$, denoting an undirected edge.

There are at most $1000$ test cases and $\sum n, \sum m \le 1.5 \times 10^6$.
输出解释
For each test case, output an integer $S = (\sum\limits_{i=1}^{n}i\cdot z_i) \text{ mod } (10^9 + 7)$, where $z_i$ is the weight of $G_i$.
输入样例
1
3 2
1 2 3
1 2
2 3
输出样例
20
来自杭电HDUOJ的附加信息
Author zimpha
Recommend wange2014

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

源链接: HDU-5739

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

共提交 0

通过率 --%
时间上限 内存上限
10000/5000MS(Java/Others) 65536/65536K(Java/Others)