Master of Subgraph

Problem E. Master of Subgraph
You are given a tree with n nodes. The weight of the i-th node is wi. Given a positive integer m, now you need to judge that for every integer i in [1,m] whether there exists a connected subgraph which the sum of the weights of all nodes is equal to i.
Input The first line contains an integer T (1 ≤ T ≤ 15) representing the number of test cases. For each test case, the first line contains two integers n (1 ≤ n ≤ 3000) and m (1 ≤ m ≤ 100000), which are mentioned above. The following n−1 lines each contains two integers ui and vi (1 ≤ ui,vi ≤ n). It describes an edge between node ui and node vi. The following n lines each contains an integer wi (0 ≤ wi ≤ 100000) represents the weight of the i-th node. It is guaranteed that the input graph is a tree.
Output For each test case, print a string only contains 0 and 1, and the length of the string is equal to m. If there is a connected subgraph which the sum of the weights of its nodes is equal to i, the i-th letter of string is 1 otherwise 0.
Example
standard input standard output
2 4 10 1 2 2 3 3 4 3 2 7 5 6 10 1 2 1 3 2 5 3 4 3 6 1 3 5 7 9 11
0110101010 1011111010
分析:考虑点分治;

   如果选树根,那么这个树里面选任何点父亲都会选到,所以会把父亲的状态传过来;

   注意dfs回退的时候再把自己状态传给父亲,传状态可以bitset加速;

   如果不选树根,分治处理;

   题目同hdu 5909(异或和为m的方案数)

posted @ 2018-04-16 17:12  mxzf0213  阅读(468)  评论(0编辑  收藏  举报