Shorten Diameter


Time limit : 2sec / Stack limit : 256MB / Memory limit : 256MB

Score : 600 points

Problem Statement

Given an undirected tree, let the distance between vertices u and v be the number of edges on the simple path from u to v. The diameter of a tree is the maximum among the distances between any two vertices. We will call a tree good if and only if its diameter is at most K.

You are given an undirected tree with N vertices numbered 1 through N. For each i(1≦iN−1), there is an edge connecting vertices Ai and Bi.

You want to remove zero or more vertices from the tree, so that the resulting tree is good. When a vertex is removed, all incident edges will also be removed. The resulting graph must be connected.

Find the minimum number of vertices that you need to remove in order to produce a good tree.

Constraints

  • 2≦N≦2000
  • 1≦KN−1
  • 1≦AiN,1≦BiN
  • The graph defined by Ai and Bi is a tree.

Input

The input is given from Standard Input in the following format:

N K
A1 B1
A2 B2
:
AN−1 BN−1

Output

Print the minimum number of vertices that you need to remove in order to produce a good tree.


Sample Input 1

6 2
1 2
3 2
4 2
1 6
5 6

Sample Output 1

2

The tree is shown below. Removing vertices 5 and 6 will result in a good tree with the diameter of 2.


Sample Input 2

6 5
1 2
3 2
4 2
1 6
5 6

Sample Output 2

0

Since the given tree is already good, you do not need to remove any vertex.

分析:虽然没做出来,不过看了陈高远大牛的代码还是可以yy一下的。

可以先求出任意两点间的距离(dfs),然后考虑最优情况是左右子树平衡的时候(有2种情况),遍历至最优情况即可

aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAbsAAAEhCAIAAABp9plsAAAMwElEQVR4nO3d21pjNwwG0Lz/S6cX0zIpJMHx9kGW1rrsB2xZkv8EOjPc7gC0ue0uAOAYEhOglcQEaCUxAVpJTIBWEhOglcQEaCUxAVpJTIBWEhOglcQEaCUxAVpJTIBWEhOglcQEaCUxAVpJTIBWEhOglcQEaCUxAVpJTIBWEpN1bm/trg5+Z02Zqz0TpSfxWU1muZJ9cpOYLCXjjco7uUk01pHBhmec0CQOu8hIk9JNaBKERWSYqbkmNInAFjLGgkQTmmxnBRlgWZYJTfayf1y1OMWEJhtZPi7Zkl9Ck11sHpdITEqxefTbmFxCky2sHf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Cccm4bnS90h0/if/0dR6srsCtxUVAWORU8QQ3l8Y8L/+2HV773YN+f4JsuL85Qpz4fDX0S+NvH2WLyBNd9Tag0Az8fwSA+MfO0wPjKUAASMZ4ASMkCAyAlCwyAlCwwAFKywABIyQIDICULDICULDAAUrLAAEjJAgMgJQsMgJQsMABSssAASMkCAyAlCwyAlCwwAFKywABIyQIDICULDICU/gezVm8/FetT5gAAAABJRU5ErkJggg==" alt="" />

代码:

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <climits>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <vector>
#include <list>
#include <ext/rope>
#define rep(i,m,n) for(i=m;i<=n;i++)
#define rsp(it,s) for(set<int>::iterator it=s.begin();it!=s.end();it++)
#define vi vector<int>
#define pii pair<int,int>
#define mod 1000000007
#define inf 0x3f3f3f3f
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define ll long long
#define pi acos(-1.0)
const int maxn=2e3+;
const int dis[][]={{,},{-,},{,-},{,}};
using namespace std;
using namespace __gnu_cxx;
ll gcd(ll p,ll q){return q==?p:gcd(q,p%q);}
ll qpow(ll p,ll q){ll f=;while(q){if(q&)f=f*p;p=p*p;q>>=;}return f;}
int n,m,a[maxn][maxn],mi,cnt;
vi p[maxn];
pii q[maxn];
void dfs(int root,int pre,int now,int s)
{
a[root][now]=s;
for(int x:p[now])
{
if(x!=pre)dfs(root,now,x,s+);
}
}
int main()
{
int i,j,k,t;
mi=inf;
scanf("%d%d",&n,&k);
rep(i,,n-){
scanf("%d%d",&j,&t);
p[j].pb(t),p[t].pb(j);
q[i].fi=j,q[i].se=t;
}
rep(i,,n)dfs(i,-,i,);
rep(i,,n)
{
cnt=;
rep(j,,n)
if(*a[i][j]>k)cnt++;
mi=min(mi,cnt);
}
rep(i,,n-)
{
cnt=;
rep(j,,n)
if(*min(a[j][q[i].fi],a[j][q[i].se])+>k)
cnt++;
mi=min(mi,cnt);
}
printf("%d\n",mi);
//system ("pause");
return ;
}

Shorten Diameter的更多相关文章

  1. AtCoder Grand Contest 001 C Shorten Diameter 树的直径知识

    链接:http://agc001.contest.atcoder.jp/tasks/agc001_c 题解(官方): We use the following well-known fact abou ...

  2. ACC 001 C - Shorten Diameter 图论

    题目: Problem Statement Given an undirected tree, let the distance between vertices \(u\) and \(v\) be ...

  3. AGC001 C - Shorten Diameter【枚举】

    一开始没看到要保证最后是树--所以一定要从叶子开始删 枚举重心,如果k是偶数,那么按当前重心提起来deep大于k/2的全都要切掉,这样枚举重心然后取min即可 奇数的话就是枚举直径中间的边,然后从两边 ...

  4. AtCoderACGC001C Shorten Diameter

    Description: 给定一个\(n\)个点的树,要求删去最少的点使树的致直径不超过k Solution: 如果\(k\)为偶数,对于最终状态一定是以每一个点为根任何点的深度不能超过\(k/2\) ...

  5. RE:从零开始的AGC被虐(到)生活(不能自理)

    RE:从零开始的AGC被虐(到)生活(不能自理) 「一直注视着你,似近似远,总是触碰不到.」 --来自风平浪静的明天 AtCoder Grand Contest 001 B: Mysterious L ...

  6. AtCoder Grand Contest

    一句话题解 QwQ主要是因为这篇文章写的有点长……有时候要找某一个题可能不是很好找,所以写了这个东西. 具体的题意.题解和代码可以再往下翻._(:з」∠)_ AGC 001 C:枚举中点/中边. D: ...

  7. A*G#C001

    AGC001 A BBQ Easy 贪心. https://agc001.contest.atcoder.jp/submissions/7856034 B Mysterious Light 很nb这个 ...

  8. 【AtCoder】AGC001

    AGC001 A - BBQ Easy 从第\(2n - 1\)个隔一个加一下加到1即可 #include <bits/stdc++.h> #define fi first #define ...

  9. AGC001[BCDE] 题解

    A没意思 F太难 所以大概近期的AGC题解都是BCDE的 然后特殊情况再说 开始刷AGC的原因就是计数太差 没有脑子 好几个学长都推荐的AGC所以就开始刷了 = = 大概两天三篇的速度?[可能也就最开 ...

随机推荐

  1. 把excel数据导入mysql中

    适用:每列的数据都不是以逗号分隔. 1.在mysql建表,全部字段与表头相同且顺序一致 2.将excel另存为csv格式,用Editplus把CSV文件另存为UTF-8编码格式 3.执行load da ...

  2. Javascript:scrollWidth,clientWidth,offsetWidth的区别(转)

    网页可见区域宽:document.body.clientWidth; 网页可见区域高:document.body.clientHeight; 网页可见区域高:document.body.offsetW ...

  3. javascript中的throttle和debounce

    throttle 我们这里说的throttle就是函数节流的意思.再说的通俗一点就是函数调用的频度控制器,是连续执行时间间隔控制.主要应用的场景比如: 1.鼠标移动,mousemove 事件2.DOM ...

  4. Linux中ls命令详解

    ls命令是linux下最常用的命令之一,ls跟dos下的dir命令是一样的都是用来列出目录下的文件,下面我们就来一起看看ls的用法 英文全名:List即列表的意思,当我们学习某种东西的时候要做到知其所 ...

  5. hdu_2111_Saving HDU(贪心)

    题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=2111 题意:给你n个物品的单位体积价值和体积,求装满容量v的背包的最大价值. 题解:乍一看还以为是背包 ...

  6. ios 烟花 火焰 雨水 雪花等特效属性

    CAEmitterLayer *snowEmitter = [CAEmitterLayer layer]; //例子发射位置 snowEmitter.emitterPosition = CGPoint ...

  7. c_select 调用参数说明

    c_select 调用 1. select系统调用select系统调用是用来让我们的程序监视多个文件描述符的状态变化的.程序会停在select这里等待,直到被监视的文件描述符有某一个或多个发生了状态改 ...

  8. Boost的VS开发环境搭建

    1. 下载并解压Boost C++ Libs 下载地址: SourceForge:http://sourceforge.net/projects/boost/files/boost/1.48.0/ B ...

  9. Inno Setup入门(二)——修改安装过程中的图片

    修改安装过程中的图片 一般编译之后,安装过程中出现在左边图片是是下图这个样子的: 其实也可以修改它,只需要在setup段中作一点稍微的修改,加一行代码即可: [setup] AppName=Test ...

  10. label自适应

    //label自适应 self.label = [UILabel new]; self.label.font = [UIFont systemFontOfSize:14]; NSString *tit ...