#include<iostream>
#include<cstring>
#include<vector>
using namespace std; const int maxn=+;
int n,s,k;
vector<int> tree[maxn],nodes[maxn];
int fa[maxn];
bool covered[maxn]; void dfs(int u,int f,int d)
{
fa[u]=f;
int nc=tree[u].size();
if(nc==&&d>k) nodes[d].push_back(u);
for(int i=;i<nc;i++)
if(tree[u][i]!=f) dfs(tree[u][i],u,d+);
} void dfs2(int u,int f,int d)
{
int nc=tree[u].size();
covered[u]=true;
for(int i=;i<nc;i++)
if(tree[u][i]!=f&&d<k)
dfs2(tree[u][i],u,d+);
} int solve()
{
int ans=;
memset(covered,,sizeof(covered));
for(int d=n-;d>k;d--)
for(int i=;i<nodes[d].size();i++)
{
int u=nodes[d][i];
if(covered[u]) continue;
int v=u;
for(int j=;j<k;j++) v=fa[v];
dfs2(v,-,);
ans++;
}
return ans;
} int main()
{
int T;
cin>>T;
while(T--)
{
cin>>n>>s>>k;
for(int i=;i<=n;i++)
{
tree[i].clear();
nodes[i].clear();
}
for(int i=;i<=n-;i++)
{
int a,b;
cin>>a>>b;
tree[a].push_back(b);
tree[b].push_back(a);
}
dfs(s,-,);
cout<<solve()<<endl;
}
return ;
}

Uva 网络(Network,Seoul 2007,LA 3902)的更多相关文章

  1. Docker 外部访问容器Pp、数据管理volume、网络network 介绍

    Docker 外部访问容器Pp.数据管理volume.网络network 介绍 外部访问容器 容器中可以运行一些网络应用,要让外部也可以访问这些应用,可以通过 -P 或 -p 参数来 指定端口映射. ...

  2. Uva LA 3902 - Network 树形DP 难度: 0

    题目 https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_pr ...

  3. LA 3902 Network(树上最优化 贪心)

    Network Consider a tree network with n <tex2html_verbatim_mark>nodes where the internal nodes ...

  4. LA 3902 Network

    人生第一道图论题啊,有木有 题意: 有一个树状网络,有一个原始服务器s,它的服务范围是k 问至少再放多少台服务范围是k的服务器才能使网络中的每个节点都被覆盖掉 解法: 我们以原始服务器为根将其转化成一 ...

  5. 分子量 (Molar Mass,ACM/ICPC Seoul 2007,UVa 1586)

    解题思路: 1.将分子量用double 数组记录下来 2.将字符串存储在字符数组中,从头向后扫描,一直记住“字母”,对下一个字符进行判断,是否是数字,如果是数字:用一个整数记录,本代码中用的sum,同 ...

  6. 分子量(Molar Mass,ACM/ICPC Seoul 2007,UVa 1586)

    #include<stdio.h>#include<stdlib.h>#include<string.h>int main(){ char s[20]; scanf ...

  7. UVa 1586 - Molar Mass - ACM/ICPC Seoul 2007 - C语言

    关键在于判断数字是两位数还是单位数,其他部分没有难度. #include"stdio.h" #include"string.h" #include"c ...

  8. LA 3902 网络

    题目链接:https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_ ...

  9. uva 315 Network(无向图求割点)

    https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...

随机推荐

  1. 华东交通大学2017年ACM“双基”程序设计竞赛 1001

    Problem Description 最近流行吃鸡,那就直接输出一行"Winner winner ,chicken dinner!"(没有双引号)模板代码:#include &l ...

  2. Git 2016视频教程

    http://blog.csdn.net/biggbang/article/details/50830331

  3. 15-----jQuery补充

    jquery除了咱们上面讲解的常用知识点之外,还有jquery 插件.jqueryUI知识点 jqueryUI 官网: https://jqueryui.com/ jqueryUI 中文网: http ...

  4. (转)linux命令总结之ip命令

    linux命令总结之ip命令 原文:https://www.cnblogs.com/ginvip/p/6367803.html linux命令总结之ip命令   Linux的ip命令和ifconfig ...

  5. 在Pycharm中写python代码时光标变粗

    在练习写python代码时,不小心摁了Insert键,结果光标变粗. 如下图所示: 原因: 和word一样,在编辑文本或代码时,有两种模式:改写和插入模式. 当我们在编辑文章或者是代码时,应该将模式设 ...

  6. 几种复杂度的斐波那契数列的Java实现

    一:斐波那契数列问题的起源 13世纪初期,意大利数论家Leonardo Fibonacci在他的著作Liber Abaci中提出了兔子的繁殖问题: 如果一开始有一对刚出生的兔子,兔子的长大需要一个月, ...

  7. Reactor Pattern and Non-blocking IO--reference

    reference from:http://www.cs.bgu.ac.il/~spl051/Personal_material/Practical_sessions/Ps_12/ps12.html ...

  8. collectd 与 logstash配置

    节点 node1: 配置logstash node2: 配置collectd, collectd收集本地的信息, 通过配置将信息发送到node1节点 node1安装配置logstash rpm -iv ...

  9. sql server sql语句

    添加联合唯一索引 create unique index 索引名 on 表名(列名1,列名2……)

  10. Java 在使用@Select遇到的问题:拼接字符串将数组拼为了字符串

    Java再用@Select拼接sql语句时候, #{参数名}:是加引号的 ${参数名}:是不加引号的 例如: userIds为List或者数组,值为1,2,3,4,5 1.@Select(" ...