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的更多相关文章
随机推荐
- 2018年牛客多校寒假 第四场 F (call to your teacher) (图的连通性)
题目链接 传送门:https://ac.nowcoder.com/acm/contest/76/F 思路: 题目的意思就是判断图的连通性可以用可达性矩阵来求,至于图的存储可以用邻接矩阵来储存,求出来可 ...
- HTMLTestRunner_PY3脚本代码
HTMLTestRunner_PY3.py文件代码如下: # -*- coding: utf-8 -*- """ A TestRunner for use with th ...
- csrf的中间件
csrf的中间件 源码简略分析: def process_request(self, request): # 从cookies中获取csrf_token csrf_token = self._get_ ...
- python小感悟(初学者)
计算机语言的起源: 在计算机刚发明出来的时候,是一大堆的机械硬件,然后技术人员开发了操作系统,操作系统是最底层的软件,负责与硬件沟通,执行其他软件的命令.由于计算机只能识别0和1两种特殊的机器语言,所 ...
- 教你使用Python制作酷炫二维码
这篇文章讲的是如何利用python制作狂拽酷炫吊炸天的二维码,非常有趣哦! 可能你见过的二维码大多长这样: 普普通通,平平凡凡,没什么特色... 但,如果二维码长这样呢! 或者 这样! 是不是炒鸡好看 ...
- TimeUnit类 java.util.concurrent.TimeUnit
TimeUnit是什么? TimeUnit是java.util.concurrent包下面的一个类,表示给定单元粒度的时间段 主要作用 时间颗粒度转换 延时 常用的颗粒度 TimeUnit.DAYS ...
- Linux 修改hostname几种方式
1: hostname DB-Server --运行后立即生效(新会话生效),但是在系统重启后会丢失所做的修改 2: echo DB-Server > /proc/sys ...
- [CQOI2009]dance跳舞(最大流+二分)
[CQOI2009]dance跳舞 每个人拆成$2$个点,表示是否与喜欢的人跳舞 跳$m$首舞曲时,满足最大流为$n*m$ 二分$m$,跑最大流即可 #include<cstdio> #i ...
- 【推荐系统】知乎live入门
参考链接: 知乎推荐系统live:姚凯飞推荐系统live 目录 1.推荐概览与框架 2.细节补充 3.召回 4.排序 5.常用技能与日常工作 5.用户画像-特征工程 6.相关经验 7.推荐考试拿分路径 ...
- Windows10测试低版本IE方法
前端开发工程师可能了解IETester是一款IE多版本兼容性测试软件,但是只支持Windows Xp,Vista,7,8系统,Windows10是不支持的,网上所说的开启.net framework ...