时间限制: 5 Sec  内存限制: 128 MB
提交: 68  解决: 14
[提交] [状态] [命题人:admin]

题目描述

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.

输入

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.

输出

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.

样例输入

复制样例数据

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

树的重心:找到一个点,其所有的子树中最大的子树节点数最少,那么这个点就是这棵树的重心。
#include "bits/stdc++.h"using namespace std;
const int maxn = 3100;
int size_[maxn], sonsize[maxn], mid, val[maxn], vis[maxn];
vector<int> e[maxn];
bitset<100010> ans, s[maxn];void dfs(int now, int fa, int n) {size_[now] = 1;sonsize[now] = 0;for (auto p:e[now]) {if (vis[p] || p == fa) continue;dfs(p, now, n);size_[now] += size_[p];sonsize[now] = max(sonsize[now], size_[p]);}sonsize[now] = max(sonsize[now], n - sonsize[now]);if (sonsize[now] < sonsize[mid]) mid = now;
}void getdp(int now, int fa) {size_[now] = 1;s[now] <<= val[now];for (auto p:e[now]) {if (p == fa || vis[p]) continue;s[p] = s[now];getdp(p, now);s[now] |= s[p];size_[now] += size_[p];}
}void slove(int now) {vis[now] = 1;s[now].reset();s[now][0] = true;getdp(now, -1);ans |= s[now];for (auto p:e[now]) {if (!vis[p]) {mid = 0;dfs(p, -1, size_[now]);slove(mid);}}
}int main() {//freopen("input.txt", "r", stdin);int _;cin >> _;sonsize[0] = 0x3f3f3f3f;while (_--) {int n, m;cin >> n >> m;for (int i = 1; i <= n; i++) {e[i].clear();vis[i] = 0;}ans.reset();int x, y;for (int i = 1; i < n; i++) {cin >> x >> y;e[x].push_back(y);e[y].push_back(x);}for (int i = 1; i <= n; i++) {cin >> val[i];}mid = 0;dfs(1, -1, n);slove(mid);for (int i = 1; i <= m; i++) {printf("%d", (int) ans[i]);}puts("");}
}

转载于:https://www.cnblogs.com/albert-biu/p/10684889.html

HDU6268 Master of Subgraph相关推荐

  1. 点分治问题 ----------- 2017杭州CCPC E.Master of Subgraph[bitset+点分治]

    题目链接 题目大意: 就是给你一颗树,树上每个点都有自己的权值,问你这棵树是否存在一棵子树,子树的权值和是[1,m][1,m][1,m]里面的,对于[1,m][1,m][1,m]里面的数,如果出现过就 ...

  2. git 创建分支并合并到master 上

    1 创建一个dev的分支 git branch dev 2 切换到dev 分支上 git checkout dev (创建并切换是git checkout -b 分支名) -------------- ...

  3. 查询Master下的系统表和系统视图获取数据库的信息和简单的渗透测试

    在SQL中可以通过查询Master下的系统表(sys)和系统视图(information_schema)获取数据库的信息.SQL2000和SQL2005的结构略有不同. 系统表结构参考系统表详细说明. ...

  4. git ssh创建分支_Git(2):在gitlab中创建开发用户,以及master分支的安全管理

    一.创建用户 1.创建管理gitlab的开发人员的用户 2.配置用户信息 3.将用户添加到java-daem组中 4.用户登录成功后,在用户界面为用户添加ssh认证 5.在linux主机中将maste ...

  5. Blender程序性纹理学习教程大师班 Creative Shrimp – Procedural Texturing Blender Master Class

    标题:创意虾-程序纹理Blender大师班 信息: 什么是程序纹理? 程序纹理将简单的数学转换为无限的真实感着色器,具有无限的多样性和分辨率. 超越看起来像一团像素特写的图像纹理,运用程序纹理的力量, ...

  6. c4d跟踪特效合成视频教程 Master Motion Tracking with Cinema 4D

    c4d跟踪特效合成视频教程 Master Motion Tracking with Cinema 4D MP4 |视频:h264,1280×720 |音频:aac,48000 Hz 语言:英语+机译中 ...

  7. Maya硬表面建模学习教程 Master Hard Surface Modeling in Maya 2020

    Maya硬表面建模学习教程 Master Hard Surface Modeling in Maya 2020 流派:电子学习| MP4 |视频:h264,1280×720 |音频:aac,48000 ...

  8. 新建本地仓库,同步远程仓场景,出现git branch --set-upstream-to=origin/master master 解决方法...

    1.本地创建一个本地仓库  2.关联远程端: git remote add origin git@github.com:用户名/远程库名.git 3.同步远程仓库到本地 git pull 这个时候会报 ...

  9. 完全隐藏Master Page Site Actions菜单只有管理员才可以看见

    1. 在Master Page Head 增加下面的Style <style type="text/css"> .ms-cui-tt { visibility:hidd ...

最新文章

  1. python中怎么比较两个列表-python中比较两个列表的实例方法
  2. jboss的几个常用操作
  3. 250相当于什么显卡_2K(4K)144hz显示器需要什么显卡来带? 本文将给你答案。
  4. 简述深度学习预训练和正则化
  5. 温州大学《深度学习》课程课件(十一、序列模型)
  6. 如何优雅地处理 EF Core 异常
  7. 你真的懂js获取可视区宽高吗
  8. 【C语言及程序设计】项目1-24-4:个人所得税计算器if语句版
  9. Memcached概述
  10. Windows下80端口被进程SystemPID=4占用的解决方法
  11. 《JavaScript设计模式 张》整理
  12. algorithm头文件下函数整合
  13. C/C++编程语言中操作目录及目录中文件的方法
  14. 微服务 雪崩效应 与 Hystrix 断路器使用入门
  15. webstorm激活破解方法大全
  16. 网络图结构中节点度分布的散点图
  17. ios 现有项目接入Flutter (问题集中营--少走弯路)
  18. Java 高级 多线程 线程安全 3 种常见解决方案教程.
  19. python怎么读xls文件,python读取xls文件
  20. 线性回归2020年天猫双十一销量

热门文章

  1. AAC规格(LC,HE,HEv2)及性能对比
  2. eureka server配置_Spring Boot(十):注册中心Eureka-客户端视角
  3. android读取mysql数据库文件_Android开发系列(十七):读取assets目录下的数据库文件...
  4. Tomcat8中URI不支持{}|等特殊字符解决方案
  5. 快速掌握 深度学习(Deep Learning) 常用概念术语,常用模型
  6. angular乱码_号外!Angular 中文文档已同步翻译至 7.0
  7. java中实现方法重载怎么声明_java 接口中如何声明类似于重载的方法?
  8. JavaScript文档对象模型document对象改变Html表单属性(4)
  9. SQL Sever select定制查询
  10. lisp如何绘制梯形_建筑考研 | 如何用数据库思维拓宽设计思路?(以清华考研快题为例)...