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& ...
随机推荐
- haoi2018奇怪的背包题解
题目传送门:https://www.lydsy.com/JudgeOnline/problem.php?id=5302 对于一个物品,设它体积为v,那么,在背包参数为p的情况下,它能达到gcd(v,p ...
- 根据不同环境配置pom
clean install clean package -P jt808_dev clean package -P tanway_test -X gps-parent <?xml version ...
- Sqoop Export HDFS
Sqoop Export应用场景——直接导出 直接导出 我们先复制一个表,然后将上一篇博文(Sqoop Import HDFS)导入的数据再导出到我们所复制的表里. sqoop export \ -- ...
- eclipse链接Hadoop集群时报错Error:Call From xxx/xxx.xxx.xxx.xxx to hostname1:9000 failed on connection exception
今天用eclipse连接Hadoop集群的时候突然给我报了这样一个错误:Error:Call From xxx/xxx.xxx.xxx.xxx to hostname1:9000 failed on ...
- 2 - Bootstrap-引导类-Bootstrap/ServerBootstrap
2.1 ChannelOption和属性 //设置属性 bootstrap.option("xxx", 1231231); bootstrap.attr("xxx&quo ...
- 使用Foxfly.Net读取STEP文件
Foxfly.Net是具备基本的几何建模和CAD文件读取功能.本文主要介绍读取STP/STEP文件的使用方法. 1.初始化 项目中引入FoxflyNet.dll程序集,在Program.cs中初始化建 ...
- css盒子模型 css3盒子相关样式
1.内边距(内边距在content外,边框内) 内边距属性: padding 设置所有边距 padding-bottom 底边距 padding-left ...
- substring、slice、substr的区别
首先定义一个变量便于下面测试:var str = "xx351223441"; substring: str.substring(form,to):从字符串里截取下标为form ...
- JS案例练习:图片切换+切换模式
先附图: CSS样式部分: <style> *{;} body{font-family:'Microsoft YaHei';} .menu{margin:20px auto 0; widt ...
- Check-Point-Security-Gateway-BYOL-R77.30-041.161
平台: CentOS 类型: 虚拟机镜像 软件包: checkpoint redhat smartconsole basic software security vfw 服务优惠价: 按服务商许可协议 ...