Given a non-empty tree with root R, and with weight W​i​​ assigned to each tree node T​i​​. The weight of a path from R to L is defined to be the sum of the weights of all the nodes along the path from R to any leaf node L.

Now given any weighted tree, you are supposed to find all the paths with their weights equal to a given number. For example, let's consider the tree showed in the following figure: for each node, the upper number is the node ID which is a two-digit number, and the lower number is the weight of that node. Suppose that the given number is 24, then there exists 4 different paths which have the same given weight: {10 5 2 7}, {10 4 10}, {10 3 3 6 2} and {10 3 3 6 2}, which correspond to the red edges in the figure.

Input Specification:

Each input file contains one test case. Each case starts with a line containing 0, the number of nodes in a tree, M (<), the number of non-leaf nodes, and 0, the given weight number. The next line contains N positive numbers where W​i​​ (<) corresponds to the tree node T​i​​. Then M lines follow, each in the format:

ID K ID[1] ID[2] ... ID[K]

where ID is a two-digit number representing a given non-leaf node, K is the number of its children, followed by a sequence of two-digit ID's of its children. For the sake of simplicity, let us fix the root ID to be 00.

Output Specification:

For each test case, print all the paths with weight S in non-increasing order. Each path occupies a line with printed weights from the root to the leaf in order. All the numbers must be separated by a space with no extra space at the end of the line.

Note: sequence { is said to be greater than sequence { if there exists 1 such that A​i​​=B​i​​ for ,, and A​k+1​​>B​k+1​​.

Sample Input:

20 9 24
10 2 4 3 5 10 2 18 9 7 2 2 1 3 12 1 8 6 2 2
00 4 01 02 03 04
02 1 05
04 2 06 07
03 3 11 12 13
06 1 09
07 2 08 10
16 1 15
13 3 14 16 17
17 2 18 19

Sample Output:

10 5 2 7
10 4 10
10 3 3 6 2
10 3 3 6 2
题目分析:给定一颗 并查集树(我自己取的) 求出从叶子节点出发 到根节点的权重和为要求值的一些队列
并且这些队列要以确定的顺序进行排序

最新文章

  1. C#开发微信公众平台-就这么简单(附Demo)
  2. 欢迎访问我的快站fbengine.kuaizhan.com
  3. Java多线程系列--“JUC线程池”01之 线程池架构
  4. Leveldb之version与version_set详细对比
  5. 在Android中进行单元测试遇到的问题
  6. lucene-源码分析
  7. css ul li 制作导航条
  8. Android中数据存储之SharedPreferences
  9. for循环中使用了return
  10. SharePoint Server 2007 Enterprise Key
  11. 配置PPTP服务器
  12. windows下pycharm远程调试pyspark
  13. Can&#39;t locate Params/Validate.pm in @INC (@INC contains: /usr/local/lib64/perl5 /
  14. windbg调试子进程
  15. C语言学习IDE和基本程序结构
  16. Redis初步整理
  17. elasticsearch数据结构
  18. Android wpa_supplicant 四次握手 流程分析
  19. Unable to locate Spring NamespaceHandler for XML schema namespace
  20. python 基础知识 列表的 增删改查 以及迭代取值

热门文章

  1. ES6语法:var、let、const的区别详解
  2. layui表格数据渲染SpringBoot+Thymeleaf返回的数据时报错(Caused by: org.attoparser.ParseException: Could not parse as expression: &quot;)
  3. SSL/TLS 协议运行机制概述(一)
  4. touch.js——手机端的操作手势
  5. Codeforces Round #200 (Div. 2)E
  6. django之 F与Q查询
  7. tarjan算法强连通分量的正确性解释+错误更新方法的解释!!!+hdu1269
  8. 从源码和doc揭秘——Java中的Char究竟几个字节,Java与Unicode的关系
  9. eclipse-JEE配置Tomcat并发布第一个项目
  10. 拒绝了对对象 &#39;***&#39; (数据库 &#39;BestSoftDB_P&#39;,架构 &#39;sale&#39;)的 EXECUTE 权限。