hdu6228Tree
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<cstdio>
#include<vector>
#include<cstring>
using namespace std;
const int maxn=200010;
vector<int >ve[maxn];
int plug[maxn];
int sum[maxn];
int number(int x){ //对于这里额使用的是一个数组来标记这个点是否访问过,其实也可以直接将上一个访问的点放进来进行判断就好,因为这个图也是一棵树
for(int i=0;i<ve[x].size();i++){
if(plug[ve[x][i]]) continue;
plug[ve[x][i]]=1;
sum[x]+=number(ve[x][i]);
}
return sum[x];
}
int main(){
int T,node,k,x,y;
cin>>T;
while(T--){
scanf("%d%d",&node,&k);
for(int i=0;i<=maxn+5;i++) ve[i].clear();
memset(plug,0,sizeof(plug));
for(int i=0;i<=node;i++) sum[i]=1;
for(int i=0;i<node-1;i++){
scanf("%d%d",&x,&y);
ve[x].push_back(y);
ve[y].push_back(x);
}
plug[1]=1;
number(1);
/*for(int i=1;i<node;i++) printf("%d ",sum[i]);
printf("%d\n",sum[node]);*/
int ans=0;
for(int i=1;i<=node;i++){
if(sum[i]>=k&&node-sum[i]>=k) ans++;
}
printf("%d\n",ans);
}
}
hdu6228Tree的更多相关文章
随机推荐
- redis关闭和启动
redis关闭 到redis节点目录下执行如下命令 redis-cli -p 端口号 shutdown redis启动 ./redis-server 参数 参数:redis.conf文件全路径 需要到 ...
- 什么是服务端伪造(SSRF)
什么是服务端伪造(SSRF) 原文:GitHub Pages and Single-Page Apps 译者:neal1991 welcome to star my articles-translat ...
- CondaHTTPError: HTTP 000 CONNECTION FAILED for url <https://mirrors.ustc.edu.cn/anaconda/pkg
conda安装时一直报错,换源什么的都不好使,折腾了半天,直到看到https://blog.csdn.net/u013383596/article/details/87718472 将https改为h ...
- stream benchmark 介绍
英文原版 https://www.cs.virginia.edu/stream/ref.html FAQ中有关于STREAM_ARRAY_SIZE NTIME OFFSET STREAM_TYPE的设 ...
- css 鼠标经过图片缓慢切换图片、鼠标离开缓慢还原
https://blog.csdn.net/qq_26780317/article/details/80486766 一.控制背景图片在一个圆形div内切换 .header .logo { width ...
- js格式化数字或者小数,加入千分符(此次为”,“)
function npChangeNum(num) { var tag = (num || 0).toString().split("."); tag[0] = tag[0].re ...
- 利用已控的标边界一台机器的 beacon对目标内网进行各种存活探测
本节的知识摘要: 基于常规 tcp / udp 端口扫描的内网存活探测 基于 icmp 的内网存活探测 基于 arp 的内网存活探测 加载外部脚本进行的各种存活探测 基础环境说明:: WebServe ...
- fast
# connect timeout in seconds# default value is 30sconnect_timeout=30 # network timeout in seconds# d ...
- python学习笔记(七)模块
一个python文件就是一个模块 1.标准模块 python自带的,不需要你安装的 2.第三方模块 需要安装,别人提供的,例:pip install radis 如果提示没有pip,把python下s ...
- 如何将DynamoDB的数据增量迁移到表格存储
Amazon DynamoDB是一个完全托管的NoSQL数据库服务,可以提供快速的.可预期的性能,并且可以实现无缝扩展.由于DynamoDB并可以根据实际需求对表进行扩展和收缩,这个过程既不需要停止对 ...