编程介的小学生 2017-03-30 05:03 采纳率: 20.3%
浏览 841
已采纳

Country F

As you know, in a Tree there is exactly one path between two nodes. A Forest consists of one or more Trees. Country F has N cities, some cities are connected by roads, and these cites form a Forest with at least two trees.

The king of country F is a man with special ideas. He wants to make any two trees in the forest isomorphic. We say that two trees are isomorphic if they have same structure. That is to say, if we ignore the indices of all the nodes, the two trees are the same.

For example, in the picture shown above, the middle tree and the right tree are isomorphic, but the middle tree and the left tree are not isomorphic.

Because it is expensive to build roads, the King decides only to destroy edges. But if too many roads are destroyed, people in country F will be angry, so he can destroy at most ONE road.

Now, the King asks you whether it is possible to make any two trees isomorphic, if he destroys at most one road.

Input

There are multiple cases (no more than 60). For each case, the first line is two integers N and M (2 <= N <= 10000, 0 <= M <= N - 2), giving the number of cities and number of roads. M lines follow, each with two integers x and y (0 <= x, y < N, x != y), means there is a road between city x and city y. You may assume that there is at most one road between any two cities and the cities forms a forest with at least two trees.

The last case is followed by two zeros.

Output

For each case, if it is possible for the King to make any two trees isomorphic when destroying at most one road, output "Yes", otherwise output "No".

Sample Input

9 7
0 1
0 2
1 3
3 4
3 5
6 7
6 8
9 7
0 1
1 2
1 3
3 4
3 5
6 7
6 8
5 2
0 1
1 2
0 0
Sample Output

Yes
Yes
No

  • 写回答

1条回答 默认 最新

  • threenewbee 2017-04-09 08:58
    关注
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 socket通信实现多人聊天室疑惑
  • ¥15 DEV-C++编译缺失
  • ¥33 找熟练码农写段Pyhthon程序
  • ¥100 怎么让数据库字段自动更新
  • ¥15 antv g6 力导向图布局
  • ¥15 quartz框架,No record found for selection of Trigger with key
  • ¥15 锅炉建模+优化算法,遗传算法优化锅炉燃烧模型,ls-svm会搞,后面的智能算法不会
  • ¥20 MATLAB多目标优化问题求解
  • ¥15 windows2003服务器按你VPN教程设置后,本地win10如何连接?
  • ¥15 求一阶微分方程的幂级数