第二十二篇英语翻译

重点单词:

prime adj.素数的,主要的,最优的, 理想的

vertice n.顶点

出处:https://acs.jxnu.edu.cn/contest/24/board/challenge/F

Not Assigning
描述:
You are given a tree of n vertices numbered from 1 to n, with edges numbered from 1 to n−1. A tree is a connected undirected graph without cycles. You have to assign integer weights to each edge of the tree, such that the resultant graph is a prime tree.

您被给了一棵由n个顶点组成的树,编号从1到n,边编号从1到n−1.树是一个没有循环的连通无向图。必须为树的每条边指定整数权重,以便生成的图是素数树。

A prime tree is a tree where the weight of every path consisting of one or two edges is prime. A path should not visit any vertex twice. The weight of a path is the sum of edge weights on that path.

素数树是指由一条或两条边组成的每条路径的权重为素数的树。路径不应访问任何顶点两次。路径的权重是该路径上的边权重之和。

Consider the graph below. It is a prime tree as the weight of every path of two or less edges is prime. For example, the following path of two edges: 2→1→3 has a weight of 11+2=13, which is prime. Similarly, the path of one edge: 4→3 has a weight of 5, which is also prime.

请考虑下面的图表。它是一棵素数树,因为两条或更少边的每条路径的权重都是素数。例如,以下两条边的路径:2→1.→3的权重为11+2=13,即素数。同样,一条边的路径为:4→3的权重为5,也就是素数。

 


Print any valid assignment of weights such that the resultant tree is a prime tree. If there is no such assignment, then print −1. It can be proven that if a valid assignment exists, one exists with weights between 1 and 105 as well.

打印任何有效的权重分配,使生成的树成为素数树。如果没有这样的任务,请打印−1.可以证明,如果存在有效的赋值,那么也存在权重在1到105之间的赋值。

输入:
The input consists of multiple test cases. The first line contains an integer t (1≤t≤104) — the number of test cases. The description of the test cases follows.

输入由多个测试用例组成。第一行包含一个整数t(1≤T≤104)-测试用例的数量。测试用例的描述如下。

 

The first line of each test case contains one integer n (2≤n≤105) — the number of vertices in the tree.

Then, n−1 lines follow. The i-th line contains two integers u and v (1≤u,v≤n) denoting that edge number i is between vertices u and v. It is guaranteed that the edges form a tree.

It is guaranteed that the sum of n over all test cases does not exceed 105.

每个测试用例的第一行包含一个整数n(2≤N≤105)-树中的顶点数。

 

然后,n−下面是一行。第i行包含两个整数u和v(1≤u、 五≤n) 表示边数i在顶点u和v之间。保证边形成一棵树。

 

保证所有测试用例中n的总和不超过105。

输出:
For each test case, if a valid assignment exists, then print a single line containing n−1 integers a1,a2,…,an−1 (1≤ai≤105), where ai denotes the weight assigned to the edge numbered i. Otherwise, print −1.

If there are multiple solutions, you may print any.

对于每个测试用例,如果存在有效的赋值,则打印一行,其中包含n−1整数a1,a2,…,an−1 (1≤人工智能≤105),其中ai表示分配给编号为i的边缘的重量。否则,打印−1.

 

如果有多个解决方案,您可以打印任何解决方案。

样例输入:
3
2
1 2
4
1 3
4 3
2 1
7
1 2
1 3
3 4
3 5
6 2
7 2
复制
样例输出:
17
2 5 11
-1
复制
注释:
For the first test case, there are only two paths having one edge each: 1→2 and 2→1, both having a weight of 17, which is prime.

 


The second test case is described in the statement.

It can be proven that no such assignment exists for the third test case.

对于第一个测试用例,只有两条路径各有一条边:1→2和2→1,两者的重量都是17,这就是质数。

声明中描述了第二个测试用例。

可以证明,对于第三个测试用例,不存在这样的分配。

posted @ 2022-02-17 23:37  次林梦叶  阅读(160)  评论(0)    收藏  举报