AtCoder Grand Contest 001 C
来源:互联网 发布:php一般用什么开发工具 编辑:程序博客网 时间:2024/05/29 03:57
想到边上去了、但是没有推出一定存在题解说的两种情况
C.Weuse the following well-known fact about trees.
Let T be a tree, and let D be the diameter of the tree.
Let T be a tree, and let D be the diameter of the tree.
• If D is even, there exists an vertex v of T such that for each vertex w in
T, the distance between w and v is at most D/2.
• If D is odd, there exists an edge e of T such that for each vertex w in T,
the distance between w and one of the endpoints of e is at most (D −1)/2.
Here v and e are called centers of the tree.
#include <cstdio>#include <cstring>#include <cmath>#include <cstdlib>#include <ctime>#include <iostream>#include <algorithm>#include <sstream>#include <string>#include <vector>#include <queue>#include <stack>#include <map>#include <set>#include <utility>#include <bitset>using namespace std;#define LL long long#define pb push_back#define mk make_pair#define pill pair<int, int>#define fi first#define se second#define mst(a, b)memset(a, b, sizeof a)#define REP(i, x, n)for(int i = x; i <= n; ++i)const int MOD = 1e9 + 7;const int qq = 2e3 + 10;const LL INF = 1e9 + 10;int n, k;vector<int> G[qq];int dis[qq][qq];void Dfs(int rt, int u, int fa, int dep) {dis[rt][u] = dep;int sz = (int)G[u].size();for(int i = 0; i < sz; ++i) {int v = G[u][i];if(v == fa)continue;Dfs(rt, v, u, dep + 1);}}pill pl[qq];int main(){scanf("%d%d", &n, &k);for(int a, b, i = 1; i < n; ++i) {scanf("%d%d", &a, &b);G[a].pb(b), G[b].pb(a);pl[i] = mk(a, b);}for(int i = 1; i <= n; ++i) {Dfs(i, i, -1, 0);}int minx = n;for(int i = 1; i <= n; ++i) {int cnt = 0;for(int j = 1; j <= n; ++j) {if(dis[j][i] * 2 > k)cnt++;}minx = min(minx, cnt);}for(int i = 1; i <= n - 1; ++i) {int cnt = 0;for(int j = 1; j <= n; ++j) {if(2 * min(dis[j][pl[i].fi], dis[j][pl[i].se]) + 1 > k)cnt++;}minx = min(minx, cnt);}printf("%d\n", minx);return 0;}
阅读全文
0 0
- AtCoder Grand Contest 001 C
- Atcoder Grand Contest 013C
- AtCoder Grand Contest 017 C
- 【AtCoder】 Grand Contest 018 C
- AtCoder Grand Contest 019 C
- (AtCoder Grand Contest 019) C
- 题解Atcoder Grand Contest C
- AtCoder Grand Contest 001 E
- AtCoder Grand Contest 001 E
- AtCoder Grand Contest 001 EBBQ Hard
- AtCoder Grand Contest 001 F permutation
- AtCoder Grand Contest 010
- AtCoder Grand Contest 011
- AtCoder Grand Contest 018
- AtCoder Grand Contest 018
- Atcoder Grand Contest 019
- AtCoder Grand Contest 010
- AtCoder Grand Contest 008
- @RequestMapping请求方式发生冲突时候的情况
- 微积分小糊涂,国庆节大快乐!
- Struts2中ActionContext、 ServletActionContext详解
- canvas 绘制八卦图
- 个人Blog开发学习笔记
- AtCoder Grand Contest 001 C
- Linux root 用户下 selenium 运行chrome --no-sandbox的问题的解决
- opcode 查询,opcode 汇总
- bzoj1880: [Sdoi2009]Elaxia的路线
- 软件构造 课堂笔记6
- Spring事务管理总结
- MD5加密算法
- DOS中del和rd的区别
- 机器学习笔记1绪论----教材周志华西瓜书