http://acm.hdu.edu.cn/showproblem.php?pid=2460
http://poj.org/problem?id=3694
Problem Description
A network administrator manages a large network. The network consists of N computers and M ...
分类:
其他好文 时间:
2015-03-02 13:10:41
阅读次数:
188
1.题目描述:点击打开链接
2.解题思路:本题让我长见识了。也学到了很多新的知识:LCA,多级祖先算法。如果只是单纯地将无根树转化为有根树,找到u,v的中点,再用BFS计算中线上结点的个数,那么最终会导致TLE。本题的高效算法如下:
首先求出以1为根的树的所有结点的总个数,保存在num数组中,再利用LCA算法求出u,v的公共祖先,设为LCA。找到u,v结点的中点mid.此时规定deep...
分类:
其他好文 时间:
2015-03-02 09:37:41
阅读次数:
120
原理讲解:http://dongxicheng.org/structure/lca-rmq/
在线算法模板:
/**
LCA在线算法O(nlogn)
主函数调用:
init();
tot=0,dir[1]=0;
dfs(1,1);
ST(2*n-1);
int lca=LCA(u,v);
*/
#include
#include
#include
#include
#inclu...
分类:
编程语言 时间:
2015-03-01 18:33:50
阅读次数:
168
http://acm.hdu.edu.cn/showproblem.php?pid=2586
Problem Description
There are n houses in the village and some bidirectional roads connecting them. Every day peole always like to ask like this ...
分类:
编程语言 时间:
2015-03-01 11:59:18
阅读次数:
710
传送门:A and B and Lecture Rooms题意:给定一棵树,每次询问到达点u,v距离相等的点有多少个。分析:按情况考虑:1.abs(deep[u]-deep[v])%2==1时,必定不存在到达u,v距离相等的点。2.如果deep[u]==deep[v]时,ans=n-num[lca(...
分类:
其他好文 时间:
2015-03-01 01:30:00
阅读次数:
204
题目链接:http://poj.org/problem?id=1986Farmer John's cows refused to run in his marathon since he chose a path much too long for their leisurely lifestyle...
分类:
其他好文 时间:
2015-03-01 00:13:26
阅读次数:
239
题目链接:http://poj.org/problem?id=1470Write a program that takes as input a rooted tree and a list of pairs of vertices. For each pair (u,v) the program ...
分类:
其他好文 时间:
2015-02-28 17:55:04
阅读次数:
143
题目链接:http://poj.org/problem?id=1330A rooted tree is a well-known data structure in computer science and engineering. An example is shown below:In the ...
分类:
其他好文 时间:
2015-02-28 14:20:50
阅读次数:
104
今天就这题照着别人的代码学了字典树...
这篇论文:http://wenku.baidu.com/view/d2ba836fb84ae45c3b358ca8.html介绍了各种字典树的运用,长了好多姿势,很有启发性
归纳一下字典树的应用:
检索(主要功能)
串排序
在DP中减少无效的状态转移
最长公共前缀问题(LCP)转化成LCA
tire+KMP 构成AC自动机数据结构
...
分类:
其他好文 时间:
2015-02-28 08:57:53
阅读次数:
165
HDU 2586 How far away ? (离线LCA Tarjan算法模板)...
分类:
编程语言 时间:
2015-02-25 22:26:58
阅读次数:
206