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的方案数)

Master of Subgraph的更多相关文章

  1. [HDU6268]Master of Subgraph

    [HDU6268]Master of Subgraph 题目大意: 一棵\(n(n\le3000)\)个结点的树,每个结点的权值为\(w_i\).给定\(m(m\le10^5)\),对于任意\(i\i ...

  2. 算法学习分析-点分治 HDU 6269 Master of Subgraph

    首先给出定义 点分治是一种处理树上路径的工具 挂出一道题目来:Master of Subgraph 这道题目让你求所有联通子图加和所能产生数字,问你1到m之间,那些数字可以被产生 这道题目,假如我们利 ...

  3. hdu 6268 Master of Subgraph(点分治+bitset)

    You are given a tree with n nodes. The weight of the i-th node is wi. Given a positive integer m, no ...

  4. HDU - 6268: Master of Subgraph (分治+bitset优化背包)

    题意:T组样例,给次给出一个N节点的点权树,以及M,问连通块的点权和sum的情况,输出sum=1到M,用0或者1表示. 思路:背包,N^2,由于是无向的连通块,所以可以用分治优化到NlgN. 然后背包 ...

  5. HDU 6268 Master of Subgraph (2017 CCPC 杭州 E题,树分治 + 树上背包)

    题目链接  2017 CCPC Hangzhou  Problem E 题意  给定一棵树,每个点有一个权值,现在我们可以选一些连通的点,并且把这点选出来的点的权值相加,得到一个和. 求$[1, m] ...

  6. CCPC 2016 杭州 E. Master of Subgraph(点分治+bitset优化DP)

    题目链接:http://acm.hdu.edu.cn/downloads/CCPC2018-Hangzhou-ProblemSet.pdf 题意:给定一棵有 n 个结点的树和一个数 m,对于 i ∈ ...

  7. The 2017 China Collegiate Programming Contest, Hangzhou Site Solution

    A: Super_palindrome 题面:给出一个字符串,求改变最少的字符个数使得这个串所有长度为奇数的子串都是回文串 思路:显然,这个字符串肯定要改成所有奇数位相同并且所有偶数位相同 那统计一下 ...

  8. 2017 CCPC杭州 题解

    2017CCPC杭州题目PDF Problem A. Super-palindrome 题解: 给你一个字符串,每一步可以将一个字符替换为另一个字符,问你最少多少步可以使得,该字符串任意奇数子串为回文 ...

  9. ROS知识(20)----使用Master_API查询Master管理的节点话题服务内容

    在一些应用中会需要获取master的uri地址,发布的话题,订阅的话题,发布的服务,节点的信息等等.这些功能我们通常可一通过rosnode list, rosnode info, rostopic l ...

随机推荐

  1. bzoj258 [USACO 2012 Jan Gold] Bovine Alliance【巧妙】

    传送门1:http://www.usaco.org/index.php?page=viewproblem2&cpid=111 传送门2:http://www.lydsy.com/JudgeOn ...

  2. AC自动机 HDOJ 2222 Keywords Search

    题目链接 题意:每个文本串的出现次数 分析:入门题,注意重复的关键字算不同的关键字,还有之前加过的清零.   新模板,加上last跑快一倍 #include <bits/stdc++.h> ...

  3. java中实参与形参的概念

    形参: public void fun(形参类型 形参名){ ... } 实参: public static void main(String[] args){ 类 对象名=new 类(); 对象名. ...

  4. AJPFX总结Java 类与对象的初始化

    面试的时候,经常会遇到这样的笔试题:给你两个类的代码,它们之间是继承的关系,每个类里只有构造器方法和静态块,它们只包含一些简单的输出字符串到控制台的代码,然后让我们写出正确的输出结果.这实际上是在考察 ...

  5. js中,浏览器中不同元素位置属性解析

    offset()   只对可见元素有效,获取匹配元素在当前视口的相对偏移,返回的对象有两个整型属性,top和left,像素计算: position() 相对父元素的偏移,position.left   ...

  6. iOS Programming UINavigationController

    iOS Programming UINavigationController the Settings application has multiple related screens of info ...

  7. 镜像中的 Everything, GnomeLive ,KdeLive ,livecd ,NetInstall的区别?

    everything: 对完整版安装盘的软件进行补充,集成所有软件 GnomeLive , GNOME桌面版 KdeLive , KDE桌面版 livecd 光盘上运行的系统 ,NetInstall ...

  8. SQL转Java代码小工具

    工作中使用SQL的时候很多,当使用hibernate的时候,经常遇到多行的SQL,通常在PL/SQL或其他地方写好SQL,测试没问题后,需要将SQL写到程序代码中,多行SQL需要拼接字符串,手动一行行 ...

  9. JavaScript回文数

    基本解决方案 function palindrome(str) { return str.replace(/[\W_]/g, '').toLowerCase() === str.replace(/[\ ...

  10. 拦截导弹问题(Noip1999)

    1322:[例6.4]拦截导弹问题(Noip1999) 时间限制: 1000 ms         内存限制: 65536 KB提交数: 3843     通过数: 1373 [题目描述] 某国为了防 ...