一、前言

前两天沈阳重现,经过队友提点,得到3题的成绩,但是看到这题下意识觉得题目错了,最后发现实际上是题目读错了。。。。GG

感觉自己前所未有的愚蠢了。。。。不过题目读对了也是一道思维题,但是很好理解。

二、题意

对于一个无相无环图,要求找出若干边,满足“这些边被至少K个不同的点集在互相联通的时候访问到”。或者说“这些边都包含在K个不同的点集个字组成的联通快里面”。

三、题解

考虑如何表示一个边,以及这条边两边的点的数量?(这是一棵树)
作为一颗树,就有树边概念,因而可以认为“该树包括他自己在内在树的一边”,“其他节点在树边的另一边”

因而,统计下,有多少符合要求的树边就可以了。具体实现见代码:

 #include<bits/stdc++.h>
using namespace std; const long long MAXN=+;
int child[MAXN];
vector<int>G[MAXN];
long long n,k;
long long ans=; void dfs(int now,int last)
{
int len=G[now].size();
for(int i=;i<len;++i)
{
int tar=G[now][i];
if(tar==last)continue;
dfs(tar,now);
child[now]+=child[tar];
} child[now]++;
if(child[now]>=k&&n-child[now]>=k)ans++; } void init()
{
// memset(child,0,sizeof(child));
ans=;
cin>>n>>k;
for(int i=;i<=n;++i)G[i].clear(),child[i]=;
for(int i=;i<n;++i)
{
int a,b;
cin>>a>>b;
G[a].push_back(b);
G[b].push_back(a); }
dfs(,);
cout<<ans<<endl; } int main()
{
cin.sync_with_stdio(false);
int ca;cin>>ca;
while(ca--)init(); return ;
}

HDU 6228 tree 简单思维树dp的更多相关文章

  1. [HDU 5293]Tree chain problem(树形dp+树链剖分)

    [HDU 5293]Tree chain problem(树形dp+树链剖分) 题面 在一棵树中,给出若干条链和链的权值,求选取不相交的链使得权值和最大. 分析 考虑树形dp,dp[x]表示以x为子树 ...

  2. HDU 5293 Tree chain problem 树形dp+dfs序+树状数组+LCA

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5293 题意: 给你一些链,每条链都有自己的价值,求不相交不重合的链能够组成的最大价值. 题解: 树形 ...

  3. HDU 6228 - Tree - [DFS]

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6228 Time Limit: 2000/1000 MS (Java/Others) Memory Li ...

  4. hdu 1520 Anniversary party 基础树dp

    Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission( ...

  5. HDU-6035:Colorful Tree(虚树+DP)

    这里有三道长得像的题: 一:HDU6036: There is a tree with nn nodes, each of which has a type of color represented ...

  6. HDU 5002 Tree(动态树LCT)(2014 ACM/ICPC Asia Regional Anshan Online)

    Problem Description You are given a tree with N nodes which are numbered by integers 1..N. Each node ...

  7. HDU 4757 Tree(可持续化字典树,lca)

    题意:询问树上结点x到结点y路上上的权值异或z的最大值. 任意结点权值 ≤ 2^16,可以想到用字典树. 但是因为是询问某条路径上的字典树,将字典树可持续化,字典树上的结点保存在这条路径上的二进制数. ...

  8. HDU 5293 Tree chain problem 树形DP

    题意: 给出一棵\(n\)个节点的树和\(m\)条链,每条链有一个权值. 从中选出若干条链,两两不相交,并且使得权值之和最大. 分析: 题解 #include <cstdio> #incl ...

  9. HDU 5125 magic balls(线段树+DP)

    magic balls Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total ...

随机推荐

  1. electron 集成 SQLCipher

    mac 安装 brew /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/m ...

  2. <probing> 元素指定扩展Asp.Net加载程序集位置

    下面的示例说明如何指定运行库应在其中搜索程序集的应用程序基子目录.     <configuration> <runtime> <assemblyBinding xmln ...

  3. 自动布局库--Masonry使用

    参考资料(戳这里): >  Masonry官网 >  Masonry介绍与使用实践(快速上手Autolayout) >  iOS 开发实践之 Auto Layout >  Ma ...

  4. iOS开发ReactiveCocoa学习笔记(六)

    RAC操作方法三. demo地址:https://github.com/SummerHH/ReactiveCocoa.git doNext deliverOn timeout interval del ...

  5. 实现一个Promise.all

    用js自己实现一个Promise.all let promiseAll = (promises) => { return new Promise((resolve, reject) => ...

  6. [AngularJS] $location 服务简介

    参考博客:  https://www.cnblogs.com/gaoruixin/p/6070502.html 简介 $location服务解析在浏览器地址栏中的URL(基于window.locati ...

  7. <转载>为什么VR不可能成功?

    这是一个来自Quora的回答,我把要点总结翻译了下,供大家参考批判. How big and issue the nausea problem for Virtual Reality products ...

  8. Winform调整DEV控件高度

  9. php之cURL惯用

    1.php cURL的强大:PHP 支持 Daniel Stenberg 创建的 libcurl 库,能够连接通讯各种服务器.使用各种协议.libcurl 目前支持的协议有 http.https.ft ...

  10. iterable -------JavaScript

    本文摘要:http://www.liaoxuefeng.com/ 遍历Array可以采用下标循环,遍历Map和Set就无法使用下标.为了统一集合类型,ES6标准引入了新的iterable类型,Arra ...