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

建议使用的浏览器:

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

5599:GTW likes tree

题目描述
GTW has a tree of $n$ nodes, in which $m$ nodes are special nodes. The value of node $i$ is $v_i$.

$Dis(x, y)$ is defined as the greatest common divisor of the nodes in the chain between node $x$ and node $y$.

$Jabby(x, y)$ is defined as the number of special nodes in the chain between node $x$ and node $y$.

You are asked to calculate the value of $ans$, which is defined as follow.

$ans=\prod_{i=1}^{n}\prod_{j=i}^{n}max(1,Dis(i,j)*min(1,jabby(i,j)))$

Because $ans$ could be very large, you only need to print $ans$ modulo $10 ^ 9 + 7$.
输入解释
The first line of the input file contains an integer $T$, indicating the number of test cases. ($T\leq 6$)

For each test case, there are $n + m + 2$ lines in the input file.

The first line of each test case contains a number $n$ which indicates the number of the nodes of GTW’s tree. ($1\leq n\leq 200000$)

In each line of the following $n - 1$ lines, there are two numbers $x$ and $y$ which indicate that there is an undirected line between node $x$ and node $y$.

The next line contains $n$ integers, $v_1,v_2,...,v_n$, in which $v_i$ indicates the value of node $i$. ($1\leq v_i\leq100000$)

The next line contains a number $m$ which indicates the number of special nodes.

Then in each line of the following $m$ lines, there are an integer $g$ which indicates that node $g$ is a special node.

The data guarantees that the $m$ given nodes differ from each other.
输出解释
In the output file, there should be exactly $T$ lines, each of which contains exactly one integer $ans$, which is defined above.
输入样例
1
2
1 2
2 2
2
1
2
输出样例
8
提示
In the sample above, $ans = 2\times 2\times 2 = 8$.
If you need a larger stack size, 
please use #pragma comment(linker, "/STACK:102400000,102400000") and submit your solution using C++.
来自杭电HDUOJ的附加信息
Recommend hujie

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

源链接: HDU-5599

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

共提交 0

通过率 --%
时间上限 内存上限
7000/3500MS(Java/Others) 131072/131072K(Java/Others)