题意:有一棵n个点的树,在树上的点涂色,每个点涂一种颜色,一共可以涂k种颜色,

然后把同一种颜色(比如说x)的点用最优方案连起来,在连线的边涂上x颜色,问涂k次的边最多有几条

k<=500

sigma n<=200000

思路:类似边分治的思路

考虑每一条边,如果以它为中心将树分割出的两部分点数都不小于k的话这条边必定对答案有贡献

这场都是队友写的,划水真爽

 #include <stdio.h>
#include <vector>
#include <algorithm>
#include <string.h>
#include <limits.h>
#include <string>
#include <iostream>
#include <queue>
#include <math.h>
#include <stack>
#include <map>
#define left (now<<1)
#define right ((now<<1)+1)
#define mid ((l+r)>>1)
using namespace std;
typedef long long int lint; const int MAXN = 2e5 + ;
const int MOD = 1e9 + ;
const int EPS = 1e-; int n,t,s[MAXN];
int ans1,ans2,ans,k;
vector<int> g[MAXN]; int dfs(int fa,int now){
s[now] = ;
if(g[now].size() == && now != ){ return s[now];}
for(int i = ; i < g[now].size(); ++i){
if(g[now][i] != fa){
s[now] += dfs(now,g[now][i]);
}
}
return s[now];
} int main(){
scanf("%d",&t);
while(t--){
scanf("%d%d",&n,&k); memset(s,,sizeof(s)); ans = ;
for(int i = ; i <= n; ++i){g[i].clear();}
for(int i = ; i < n; ++i){
int u,v; scanf("%d%d",&u,&v);
g[u].push_back(v); g[v].push_back(u);
}
dfs(-,);
// for(int i = 1; i <= n; ++i){
// i != n ? printf("%d ",s[i]) : printf("%d\n",s[i]);
// }
for(int i = ; i <= n; ++i){
int t1 = s[i]; int t2 = n - t1;
if(t1 >= k && t2 >= k) ++ans;
}
printf("%d\n",ans);
}
return ;
}

最新文章

  1. tomcat发布脚本
  2. iOS与Html5和JS之间的交互---学习笔记五
  3. Ubuntu14.04下解压rar压缩包
  4. poj 1556 The Doors
  5. linux系统终端命令提示符设置(PS1)记录
  6. 弄清const与指针、引用之间的关系
  7. jq 判断输入数字
  8. .net mvc mssql easyui treegrid 及时 编辑 ,支持拖拽
  9. Oracle-orclEXORIM
  10. bzoj4035 [HAOI2015]数组游戏
  11. CDRAF之Service mesh
  12. 美人鱼 hdu 5784
  13. python使用tkinter写带界面的工具
  14. 使用GIT SUBTREE集成项目到子目录(转)
  15. elasticsearch 请求体查询方式整理
  16. map reduce相关程序
  17. 分享6款国内、外开源PHP轻论坛CMS程序
  18. ubuntu 18 设置语言环境
  19. Zookeeper -- 本地\完全分布式 搭建
  20. MYSQL复习笔记5-select-from-where子句

热门文章

  1. UVA 11584 Partitioning by Palindromes 划分回文串 (Manacher算法)
  2. 读懂 Deployment YAML【转】
  3. Ibatis入门基本语法
  4. C# 队列Queue
  5. Xcode及Mac快捷键
  6. [LUOGU] P1828 香甜的黄油 Sweet Butter
  7. MySQL 上移/下移/置顶
  8. verilog behaviral modeling -- procedural timing contronls
  9. 【ios】IOS返回3824错误
  10. python中的list、tuple和dictionary