BZOJ4813 [Cqoi2017]小Q的棋盘
来源:互联网 发布:学程序员初中生可以吗 编辑:程序博客网 时间:2024/05/15 00:36
找以起点为起点的一个最长链,最优一定是在最长链上不走回头路的,所以相当于最长链上的边代价是1,非最长链的边代价是2(因为要走回去),每付出一次代价就可以使访问到的点数+1,那么贪心即可
#include<iostream>#include<cstring>#include<ctime>#include<cmath>#include<algorithm>#include<iomanip>#include<cstdlib>#include<cstdio>#include<map>#include<bitset>#include<set>#include<stack>#include<vector>#include<queue>using namespace std;#define MAXN 1010#define MAXM 1010#define ll long long#define eps 1e-8#define MOD 1000000007#define INF 1000000000struct vec{int to;int fro;};vec mp[MAXN*2];int tai[MAXN],cnt;int n,k;int mx[MAXN];int ans=1;inline void be(int x,int y){mp[++cnt].to=y;mp[cnt].fro=tai[x];tai[x]=cnt;}inline void bde(int x,int y){be(x,y);be(y,x);}void dfs(int x,int f){int i,y;for(i=tai[x];i;i=mp[i].fro){y=mp[i].to;if(y!=f){dfs(y,x);mx[x]=max(mx[x],mx[y]+1);}}}int main(){int i,x,y;scanf("%d%d",&n,&k);for(i=1;i<n;i++){scanf("%d%d",&x,&y);bde(x+1,y+1);}dfs(1,0);ans+=min(mx[1],k);k-=min(mx[1],k);while(ans<n&&k>=2){ans++;k-=2;}printf("%d\n",ans);return 0;}/**/
0 0
- 【CQOI2017】bzoj4813 小Q的棋盘
- BZOJ4813: [Cqoi2017]小Q的棋盘
- BZOJ4813 [Cqoi2017]小Q的棋盘
- bzoj4813: [Cqoi2017]小Q的棋盘
- 【BZOJ4813】 [Cqoi2017]小Q的棋盘
- 【BZOJ4813】小Q的棋盘(CQOI2017)-贪心+DFS
- 贪心——BZOJ4813/Luogu3698 [CQOI2017]小Q的棋盘
- bzoj4813 [Cqoi2017]小Q的棋盘 树上DP
- cqoi2017,bzoj4813小Q的棋盘(树形dp或瞎搞)
- 【CQOI2017】小Q的棋盘
- CQOI2017 小Q的棋盘
- [bzoj4813][树形dp]小Q的棋盘
- bzoj 4813 [Cqoi2017]小Q的棋盘
- BZOJ 4813 [Cqoi2017]小Q的棋盘
- 4813: [Cqoi2017]小Q的棋盘
- BZOJ 4813 [Cqoi2017]小Q的棋盘
- 4813: [Cqoi2017]小Q的棋盘
- [BZOJ 4813][Cqoi2017]小Q的棋盘:TreeDP
- webview加载https页面图片不能显示问题
- android学习杂记.9
- IntelliJ IDEA 2016 3.6 激活
- 第七天2017/04/14(C++对C的扩充,C++与C的区别,C++的基础知识)
- 二、zedboard 交叉工具链安装
- BZOJ4813 [Cqoi2017]小Q的棋盘
- textview字数限制
- iis部署提示未能写入输出文件“c:\Windows\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files 解决方案
- ZooKeeper 核心模块代码浅析
- 在开发过程中为什么需要写存储过程
- 9个最常见IE的Bug及其fix
- HttpUrlConnection获取服务器数据,并返回数据
- C++多态知多少?
- ARP报文解析