CF519E A and B and Lecture Rooms】的更多相关文章

最近很颓……难题想不动……水题写不对,NOIP怕是…
题目链接:E. A and B and Lecture Rooms 题目大意 给定一颗节点数10^5的树,有10^5个询问,每次询问树上到xi, yi这两个点距离相等的点有多少个. 题目分析 若 x==y 直接返回 n. 先求出 x, y 两个点的中点. 先求出 LCA(x, y) = z,假设 Depth[x] >= Depth[y] ,若Depth[x] == Depth[y] ,那么 z 就是它们的中点. 答案就是,n - Size[fx] - Size[fy],fx 是从x向上跳,一直跳…
转载请注明出处: http://www.cnblogs.com/fraud/          ——by fraud E. A and B and Lecture Rooms A and B are preparing themselves for programming contests. The University where A and B study is a set of rooms connected by corridors. Overall, the University ha…
A and B and Lecture Rooms time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output A and B are preparing themselves for programming contests. The University where A and B study is a set of rooms co…
Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u Submit Status Practice CodeForces 519E Description A and B are preparing themselves for programming contests. The University where A and B study is a set of rooms connected…
A and B are preparing themselves for programming contests. The University where A and B study is a set of rooms connected by corridors. Overall, the University has n rooms connected by n - 1corridors so that you can get from any room to any other one…
题目描述 A and B are preparing themselves for programming contests. The University where A and B study is a set of rooms connected by corridors. Overall, the University has n rooms connected by n - 1 corridors so that you can get from any room to any oth…
题目:http://codeforces.com/problemset/problem/519/E 题意:给你一个n个点的树,有m个询问(x,y),对于每个询问回答树上有多少个点和x,y点的距离相等 分析:对于x,y,容易知道距离相等的点是链x->y上的中点除去x.y所在子树的其他所有子树的和 于是分类: 链x->y的长度是奇数:则一定没有距离相等的点,输出0 链x->y的长度是偶数: 链上的中点Mid恰好是x,y的lca,则输出n-size[lca(x,y)的某个儿子(这个儿子是x的父…
Description 询问一个树上与两点距离相等的点的个数. Sol 倍增求LCA. 一棵树上距离两点相等,要么就只有两点的中点,要么就是与中点相连的所有点. 有些结论很容易证明,如果距离是偶数,那么他们没有中点,树上不存在距离两点相等的点. 如果中点恰好是两点LCA,那么答案就是\(n-size_x-size_y\) ,\(size_x\) 和 \(size_y\) 表示LCA的子节点中子树包含 \(u,v\) 的子节点的\(size\) 如果不是LCA,那么答案就是 \(size_{LCA…
题意: 给你一棵有n个节点的树,给你m次询问,查询给两个点,问树上有多少个点到这两个点的距离是相等的.树上所有边的边权是1. 思路: 很容易想到通过记录dep和找到lca来找到两个点之间的距离,然后分情况讨论. 一开始困扰我的问题是如果lca不是正中间的点,如何在比较低的复杂度的层面上求解中点. 倍增法lca不光可以在logn的时间复杂度内查询某两个点的lca,还可以实现在logm的时间复杂度能查询某个节点的第m个父亲节点. 算法的核心是用二进制的运算来实现查询. #include<bits/s…