#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. 安装php过程中的错误和解决方式 configure: error: jpeglib.h not found

    centos6.5 32位系统: checking for the location of libpng... yeschecking for the location of libXpm... no ...

  2. JS事件冒泡机制和兼容性添加事件

    本篇文章主要来讲讲 事件的冒泡机制 和 添加事件的几种方法. 一. JS的时间传递顺序: 捕获阶段 -> 目标阶段 -> 冒泡阶段 捕获阶段是指从父层往子层找.比如 <body> ...

  3. bash和zsh切换

    zsh切换bash bash切换zsh 切换bash chsh -s /bin/bash 切换zsh chsh -s /bin/zsh

  4. 下载安装MariaDB Galera 10.1

    因为无法访问外网, 配置官网的yum无法下载MariaDB Galera(在MariaDB 10.1 及之后内置了Galera, 不像之前那样需要独立安装) 需要在下载的包 MariaDB-10.1. ...

  5. Android 中文 API (101) —— AsyncTask

    一.结构 public abstract class AsyncTask extends Object java.lang.Object android.os.AsyncTask<Params, ...

  6. Java学习笔记--继承和多态(上)

    1.通过继承来开发超类(superclass) 2.使用super 关键词唤起超类的构造方法 3.在超类中覆盖方法 4.区分override和overload 5.在Object类中探索toStrin ...

  7. ASP Session的功能的缺陷以及解决方案

    转http://www.cnblogs.com/jhy55/p/3376925.html 目前ASP的开发人员都正在使用Session这一强大的功能,但是在他们使用的过程中却发现了ASP Sessio ...

  8. hibernate课程 初探单表映射1-7 hibernate配置文件新建

    hibernate  配置文件新建 1 右键src==>new==>other==>hibernate configuration File==>next==>next= ...

  9. javascript实现多线程提升项目加载速度

    以前大家都认为js是单线程执行的,假如我们要执行一些耗时的操作,比如加载一张很大的图片,我们可能需要一个进度条来让用户进行等待,在等待的过程中,整个js线程会被阻塞,后面的代码不能正常运行,这可能大大 ...

  10. C#对话框-打开和保存对话框(转)

    //打开文件            OpenFileDialog openFileDialog = new OpenFileDialog();            openFileDialog.In ...