CF1025D.Recovering BST
提高+/省选-
通过率:0%
时间限制:1.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Dima the hamster enjoys nibbling different things: cages, sticks, bad problemsetters and even trees!
Recently he found a binary search tree and instinctively nibbled all of its edges, hence messing up the vertices. Dima knows that if Andrew, who has been thoroughly assembling the tree for a long time, comes home and sees his creation demolished, he'll get extremely upset.
To not let that happen, Dima has to recover the binary search tree. Luckily, he noticed that any two vertices connected by a direct edge had their greatest common divisor value exceed 1.
Help Dima construct such a binary search tree or determine that it's impossible. The definition and properties of a binary search tree can be found here.
仓鼠迪马喜欢啃各种东西:笼子、木棍、糟糕的出题人,甚至还有树!
最近,他发现了一棵二叉搜索树,并本能地啃掉了它的所有边,从而打乱了顶点之间的连接关系。迪马知道,如果一直精心搭建这棵树的安德鲁回家后看到自己的作品被毁,一定会极度沮丧。
为了避免这种情况发生,迪马必须恢复这棵二叉搜索树。幸运的是,他注意到:任意两个由一条直接边相连的顶点,其最大公约数(GCD)值均大于 1。
请帮助迪马构造这样的一棵二叉搜索树,或判定其不可能存在。二叉搜索树的定义与性质可参见此处。
输入格式
The first line contains the number of vertices n (2≤n≤700).
The second line features n distinct integers ai (2≤ai≤109) — the values of vertices in ascending order.
第一行包含顶点数量 n(2≤n≤700)。
第二行包含 n 个互不相同的整数 ai(2≤ai≤109),即按升序排列的顶点值。
输出格式
If it is possible to reassemble the binary search tree, such that the greatest common divisor of any two vertices connected by the edge is greater than 1, print "Yes" (quotes for clarity).
Otherwise, print "No" (quotes for clarity).
如果可以重新构造这棵二叉搜索树,使得每条边所连接的两个顶点的最大公约数大于 1,则输出 "Yes"(引号仅用于明确显示)。
否则,输出 "No"(引号仅用于明确显示)。
输入输出样例
输入#1
6 3 6 9 18 36 108
输出#1
Yes
输入#2
2 7 17
输出#2
No
输入#3
9 4 8 10 12 15 18 33 44 81
输出#3
Yes
说明/提示
The picture below illustrates one of the possible trees for the first example.

The picture below illustrates one of the possible trees for the third example.

下图展示了第一个示例中可能的树之一。

下图展示了第三个示例中可能的树之一。

输入解题思路,AI测评打分。不知道怎么写?