Uva 网络(Network,Seoul 2007,LA 3902)
#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)的更多相关文章
- Docker 外部访问容器Pp、数据管理volume、网络network 介绍
Docker 外部访问容器Pp.数据管理volume.网络network 介绍 外部访问容器 容器中可以运行一些网络应用,要让外部也可以访问这些应用,可以通过 -P 或 -p 参数来 指定端口映射. ...
- Uva LA 3902 - Network 树形DP 难度: 0
题目 https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_pr ...
- LA 3902 Network(树上最优化 贪心)
Network Consider a tree network with n <tex2html_verbatim_mark>nodes where the internal nodes ...
- LA 3902 Network
人生第一道图论题啊,有木有 题意: 有一个树状网络,有一个原始服务器s,它的服务范围是k 问至少再放多少台服务范围是k的服务器才能使网络中的每个节点都被覆盖掉 解法: 我们以原始服务器为根将其转化成一 ...
- 分子量 (Molar Mass,ACM/ICPC Seoul 2007,UVa 1586)
解题思路: 1.将分子量用double 数组记录下来 2.将字符串存储在字符数组中,从头向后扫描,一直记住“字母”,对下一个字符进行判断,是否是数字,如果是数字:用一个整数记录,本代码中用的sum,同 ...
- 分子量(Molar Mass,ACM/ICPC Seoul 2007,UVa 1586)
#include<stdio.h>#include<stdlib.h>#include<string.h>int main(){ char s[20]; scanf ...
- UVa 1586 - Molar Mass - ACM/ICPC Seoul 2007 - C语言
关键在于判断数字是两位数还是单位数,其他部分没有难度. #include"stdio.h" #include"string.h" #include"c ...
- LA 3902 网络
题目链接:https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_ ...
- uva 315 Network(无向图求割点)
https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...
随机推荐
- springMvc配置 中文api
http://7xvpsh.com1.z0.glb.clouddn.com/publish/21-2/the-dispatcher-servlet.html springmvc4.1.7:配置 复制转 ...
- java insert mysql 中文乱码
jdbc:mysql://192.168.1.77:3306/db360?useUnicode=true&characterEncoding=UTF-8 drop database if ex ...
- C# 高级编程语言
高级语言(High-level programming language)相对于机器语言(machine language,是一种指令集的体系.这种指令集,称机器码(machine code),是电脑 ...
- Maven配置默认JDK/JRE版本
1. settings.xml的profiles标签下配置 <profile> <id>jdk-1.8</id> <activation> <ac ...
- static修饰的类属性
我看书上说:static成员总是唯一存在的,并且在多个对象之间互享. 因此想到,如果我在a.php中实例化了Person.class.php这个类,并给static $name赋值,那么在b.php中 ...
- wamp 下运行Drupal慢的解决方法
1.Editing your php.ini and make realpath_cache_size=2M, 2.uncomment skip innodb in your my.cnf(my.in ...
- mui的ajax例子3
mui.get() 前端页面: <!DOCTYPE html><html><head> <meta charset="utf-8"> ...
- C++中构造函数的写法
class Circle { public: Circle(float r); private: float radius; }; Circle::Circle(float r) { radius = ...
- 【Shell脚本学习22】Shell 函数:Shell函数返回值、删除函数、在终端调用函数
函数可以让我们将一个复杂功能划分成若干模块,让程序结构更加清晰,代码重复利用率更高.像其他编程语言一样,Shell 也支持函数.Shell 函数必须先定义后使用. Shell 函数的定义格式如下: f ...
- Java有关List的stream基本操作
参考博客: https://www.jianshu.com/p/9fe8632d0bc2 Stream简介 Java 8引入了全新的Stream API.这里的Stream和I/O流不同,它更像具有I ...