编程介的小学生 2018-11-28 08:10 采纳率: 20.5%
浏览 336
已采纳

Distinct Subtrees 这个问题用什么算法可以解决呢

Problem Description
Given an unrooted tree with n nodes, the subtree is defined as a connected component of the given tree. Two subtrees are considered the same if there exists a map from nodes of one tree to another so that the edges of both trees are corresponding the same pair of nodes after mapping.
Your task is to find out how many distinct subtrees for a given unrooted tree.

Input
The input consists of multiple test cases. The first line of input contains an integer denoting the number of test cases.
For each test case, the first line contains one integer n denoting the number of nodes of the given tree. (1 <= n <= 15)
Then n-1 lines follow, each line contains two integers denoting an edge of the tree (x, y).

Output
For each test case, output the number of distinct subtrees for the given tree.

Sample Input
2
3
1 2
1 3
9
9 4
4 3
1 3
7 4
1 6
5 7
2 4
6 8

Sample Output
Case #1: 3
Case #2: 21

  • 写回答

1条回答 默认 最新

  • threenewbee 2019-02-14 23:30
    关注
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 求差集那个函数有问题,有无佬可以解决
  • ¥15 【提问】基于Invest的水源涵养
  • ¥20 微信网友居然可以通过vx号找到我绑的手机号
  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名
  • ¥65 汇编语言除法溢出问题