CF1916G.Optimizations From Chelsu
普及/提高-
通过率:0%
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
You are given a tree with n vertices, whose vertices are numbered from 1 to n . Each edge is labeled with some integer wi .
Define len(u,v) as the number of edges in the simple path between vertices u and v , and gcd(u,v) as the Greatest Common Divisor of all numbers written on the edges of the simple path between vertices u and v . For example, len(u,u)=0 and gcd(u,u)=0 for any 1≤u≤n .
You need to find the maximum value of len(u,v)⋅gcd(u,v) over all pairs of vertices in the tree.
输入格式
Each test consists of multiple test cases. The first line contains a single integer t ( 1≤t≤104 ) — the number of test cases. This is followed by their description.
The first line of each test case contains the number n ( 2≤n≤105 ) — the number of vertices in the tree.
The next n−1 lines specify the edges in the format u , v , w ( 1≤u,v≤n , 1≤w≤1012 ).
It is guaranteed that the sum of n over all test cases does not exceed 105 .
输出格式
For each test case, output a single number equal to the maximum value of len(u,v)⋅gcd(u,v) over all pairs of vertices in the tree.
输入输出样例
输入#1
4 2 1 2 1000000000000 4 3 2 6 2 1 10 2 4 6 8 1 2 12 2 3 9 3 4 9 4 5 6 5 6 12 6 7 4 7 8 9 12 1 2 12 2 3 12 2 4 6 2 5 9 5 6 6 1 7 4 4 8 12 8 9 4 8 10 12 2 11 9 7 12 9
输出#1
1000000000000 12 18 24