2017沈阳站 Tree
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6228
Tree
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others)
Total Submission(s): 1693 Accepted Submission(s):
978
significance of tree or plant, but a tree as an undirected graph in graph theory
with n nodes, labelled from 1 to n. If you cannot understand the concept of a
tree here, please omit this problem.
Now we decide to colour its nodes with k
distinct colours, labelled from 1 to k. Then for each colour i = 1, 2, · · · ,
k, define Ei as the minimum subset of edges connecting all nodes coloured by i.
If there is no node of the tree coloured by a specified colour i, Ei will be
empty.
Try to decide a colour scheme to maximize the size of E1 ∩ E2 · · · ∩
Ek, and output its size.
1000), indicating the total number of test cases.
For each case, the first
line contains two positive integers n which is the size of the tree and k (k ≤
500) which is the number of colours. Each of the following n - 1 lines contains
two integers x and y describing an edge between them. We are sure that the given
graph is a tree.
The summation of n in input is smaller than or equal to
200000.
... ∩ Ek.
4 2
1 2
2 3
3 4
4 2
1 2
1 3
1 4
6 3
1 2
2 3
3 4
3 5
6 2
0
1
#include<iostream>
#include<vector>
using namespace std;
#define maxn 300000
int n,k,cnt,ans,size[maxn],head[maxn];
struct edge{
int to,next;
}e[maxn];
vector<int>ve[maxn];
void add(int u,int v)
{
e[++cnt].to=v;
e[cnt].next=head[u];
head[u]=cnt;
}
void dfs(int u,int f)
{
for(int i=;i<ve[u].size();i++)
{
int x=ve[u][i];
if(x==f)continue;
dfs(x,u);
size[u]+=size[x];
}
if(size[u]>=k&&n-size[u]>=k)ans++;
}
int main()
{
int t;
cin>>t;
while(t--)
{
cin>>n>>k;
int u,v;
for(int i=;i<=n;i++)
{
ve[i].clear();
size[i]=;
}
for(int i=;i<n;i++)
{
cin>>u>>v;
add(u,v);
ve[u].push_back(v);
ve[v].push_back(u);
}
ans=;
dfs(,);
cout<<ans<<endl;
}
return ;
}
2017沈阳站 Tree的更多相关文章
- 2016ACM/ICPC亚洲区沈阳站-重现赛赛题
今天做的沈阳站重现赛,自己还是太水,只做出两道签到题,另外两道看懂题意了,但是也没能做出来. 1. Thickest Burger Time Limit: 2000/1000 MS (Java/Oth ...
- HDU 5950 Recursive sequence 【递推+矩阵快速幂】 (2016ACM/ICPC亚洲区沈阳站)
Recursive sequence Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Other ...
- HDU 5952 Counting Cliques 【DFS+剪枝】 (2016ACM/ICPC亚洲区沈阳站)
Counting Cliques Time Limit: 8000/4000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) ...
- HDU 5948 Thickest Burger 【模拟】 (2016ACM/ICPC亚洲区沈阳站)
Thickest Burger Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)T ...
- HDU 5949 Relative atomic mass 【模拟】 (2016ACM/ICPC亚洲区沈阳站)
Relative atomic mass Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Oth ...
- 2015ACM/ICPC亚洲区沈阳站 Pagodas
Pagodas Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Sub ...
- 2015ACM/ICPC亚洲区沈阳站 B-Bazinga
Bazinga Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Sub ...
- HDU 6227.Rabbits-规律 (2017ACM/ICPC亚洲区沈阳站-重现赛(感谢东北大学))
Rabbits Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others)Total S ...
- HDU 6225.Little Boxes-大数加法 (2017ACM/ICPC亚洲区沈阳站-重现赛(感谢东北大学))
整理代码... Little Boxes Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/O ...
随机推荐
- Java能不能通过代码干预Java垃圾回收
1.不能通过Java代码干预Java垃圾回收. 2.system.gc是请求运行垃圾回收器,不一定真的运行了垃圾回收器. 3.Java的system.gc不受代码控制. 4.影响Java虚拟机垃圾回收 ...
- V先生:信息流广告标题党必备的500个热词
稍微没有全都偏,简直仅仅只永远, 已经曾经就竟然,将要立刻刚偶然, 渐渐终于决忽然,难道连续又再三, 也许必须很非常,最太十分更马上, 越极总挺常常再,屡次一定也不还. 你一定不知道.如何.最.咋.是 ...
- 灰熊:在这6个信息流和DSP平台投放后,我总结了这些血泪经验!
笔者有幸参与公司的一款重度游戏的推广,推广以来市面上主流的信息流和DSP 平台都投过一番,今天就零零碎碎地讲讲各个平台的特点以及用户质量. 需要提前说明的是,文章的观点仅限于各个平台的 iOS 流量, ...
- mysql安装密码策略插件
https://blog.csdn.net/kk185800961/article/details/79447754 注意linux安装密码策略的插件 validate_password.so
- Mybatis学习 day02
第十六章回顾SQL99中的连接查询 1)内连接 2)外连接 3)自连接 第十七章回顾hibernate多表开发 1)一对一 2)一对多 3)多对多 第十八章 mybatis一对一映射[学生与身份证] ...
- django settings多环境配置
通常我们会把本地.线上的配置拆分,django不同环境的配置可如下: 1.在settings.py同级目录添加settings文件夹 2.把settings.py移到settings文件夹内,并重命名 ...
- java过滤emoji表情
import java.util.regex.Matcher; import java.util.regex.Pattern; public class test { /** * 表情过滤 * */ ...
- 沙箱机制(Sandboxie)
一.沙箱是什么? 沙箱是一个虚拟系统程序,沙箱提供的环境相对于每一个运行的程序都是独立的,而且不会对现有的系统产生影响. 二.沙箱的应用 (1)搭建测试环境.沙箱的应用只能访问自己的应用访问目录,而不 ...
- .net 语音,视频等格式转换
最近在做微信公众号开发的时候遇到一个问题,就是微信接收到语音消息的格式为amr,在网页上通常不能直接播放,需要先转为mp3,于是找到了一个办法,使用ffmpeg.exe,网上可以搜一下ffmpeg.e ...
- 简单搭建一个SpringBoot
1.SpringBoot下载 https://start.spring.io/ 选择工程类型,编译语言,版本,工程名称,需要支持组件等:选择好了以后点击生成项目. 之后会下载一个压缩文件,解压之后导入 ...