CF1725E.Electrical Efficiency
省选/NOI-
通过率:0%
时间限制:3.00s
内存限制:512MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
In the country of Dengkleknesia, there are N factories numbered from 1 to N. Factory i has an electrical coefficient of Ai. There are also N−1 power lines with the j-th power line connecting factory Uj and factory Vj. It can be guaranteed that each factory in Dengkleknesia is connected to all other factories in Dengkleknesia through one or more power lines. In other words, the collection of factories forms a tree. Each pair of different factories in Dengkleknesia can use one or more existing power lines to transfer electricity to each other. However, each power line needs to be turned on first so that electricity can pass through it.
Define f(x,y,z) as the minimum number of power lines that need to be turned on so that factory x can make electrical transfers to factory y and factory z. Also define g(x,y,z) as the number of distinct prime factors of GCD(Ax,Ay,Az).
To measure the electrical efficiency, you must find the sum of f(x,y,z)×g(x,y,z) for all combinations of (x,y,z) such that 1≤x<y<z≤N. Because the answer can be very large, you just need to output the answer modulo 998244353.
Note: GCD(k1,k2,k3) is the greatest common divisor of k1, k2, and k3, which is the biggest integer that simultaneously divides k1, k2, and k3.
在邓克勒克尼西亚国,共有 N 座工厂,编号从 1 到 N。工厂 i 具有电学系数 Ai。此外还有 N−1 条输电线路,其中第 j 条输电线路连接工厂 Uj 与工厂 Vj。可以保证邓克勒克尼西亚的所有工厂通过一条或多条输电线路彼此连通。换言之,这些工厂构成一棵树。邓克勒克尼西亚中任意两个不同的工厂均可借助一条或多条现有输电线路相互传输电力。但每条输电线路必须先被开启,电力才能通过。
定义 f(x,y,z) 为:使工厂 x 能够向工厂 y 和工厂 z 同时传输电力所需开启的最少输电线路数量。
定义 g(x,y,z) 为 GCD(Ax,Ay,Az) 的不同质因数的个数。
为衡量电力传输效率,你需要计算所有满足 1≤x<y<z≤N 的三元组 (x,y,z) 对应的 f(x,y,z)×g(x,y,z) 的总和。由于答案可能非常大,你只需输出该总和对 998244353 取模的结果。
注:GCD(k1,k2,k3) 表示 k1、k2 和 k3 的最大公约数,即能同时整除 k1、k2 和 k3 的最大整数。
输入格式
The first line contains a single integer N (1≤N≤2⋅105) — the number of factories in Dengkleknesia.
The second line contains N integers A1,A2,…,AN (1≤Ai≤2⋅105) — the electrical coefficients of the factories.
The j-th of the next N−1 lines contains two integers Uj and Vj (1≤Uj,Vj≤N) — a power line that connects cities Uj and Vj. The collection of factories forms a tree.
第一行包含一个整数 N(1≤N≤2⋅105)—— 表示登克勒克内西亚的工厂数量。
第二行包含 N 个整数 A1,A2,…,AN(1≤Ai≤2⋅105)—— 表示各工厂的电学系数。
接下来的 N−1 行中,第 j 行包含两个整数 Uj 和 Vj(1≤Uj,Vj≤N)—— 表示一条连接城市 Uj 与 Vj 的输电线路。这些工厂构成一棵树。
输出格式
An integer representing the sum of f(x,y,z)×g(x,y,z) for all combinations of (x,y,z) such that 1≤x<y<z≤N, modulo 998244353
一个整数,表示对所有满足 1≤x<y<z≤N 的三元组 (x,y,z),f(x,y,z)×g(x,y,z) 的和,结果对 998244353 取模。
输入输出样例
输入#1
3 1 2 3 1 2 2 3
输出#1
0
输入#2
4 6 14 6 6 1 2 2 3 2 4
输出#2
12
说明/提示
In the first example, the only (x,y,z) possible is (1,2,3). Because GCD(A1,A2,A3)=GCD(1,2,3)=1 has 0 distinct prime factors, therefore f(x,y,z)×g(x,y,z)=2×0=0.
In the second example, all triples (x,y,z) that satisfy the condition are as follows:
- (1,2,3)→f(1,2,3)×g(1,2,3)=2×1=2
- (1,2,4)→f(1,2,4)×g(1,2,4)=2×1=2
- (1,3,4)→f(1,3,4)×g(1,3,4)=3×2=6
- (2,3,4)→f(2,3,4)×g(2,3,4)=2×1=2
So the electrical efficiency is 2+2+6+2=12.
在第一个例子中,唯一可能的 (x,y,z) 是 (1,2,3)。由于 GCD(A1,A2,A3)=GCD(1,2,3)=1 有 0 个不同的质因数,因此 f(x,y,z)×g(x,y,z)=2×0=0。
在第二个例子中,所有满足条件的三元组 (x,y,z) 如下:
- (1,2,3)→f(1,2,3)×g(1,2,3)=2×1=2
- (1,2,4)→f(1,2,4)×g(1,2,4)=2×1=2
- (1,3,4)→f(1,3,4)×g(1,3,4)=3×2=6
- (2,3,4)→f(2,3,4)×g(2,3,4)=2×1=2
因此,电效率为 2+2+6+2=12。
输入解题思路,AI测评打分。不知道怎么写?