凭借记忆勉强写出的倍增LCA。http://www.lydsy.com/JudgeOnline/problem.php?id=4281/************************************************************** Problem: 4281 ...
分类:
其他好文 时间:
2015-10-12 00:24:54
阅读次数:
240
Given a binary search tree (BST), find the lowest common ancestor (LCA) of two given nodes in the BST.According to thedefinition of LCA on Wikipedia: ...
分类:
其他好文 时间:
2015-10-11 15:21:14
阅读次数:
142
SPOJ 10628. Count on a tree (树上第k大,LCA+主席树)10628. Count on a treeProblem code: COTYou are given a tree withNnodes.The tree nodes are numbered from1toN...
分类:
其他好文 时间:
2015-10-10 20:04:56
阅读次数:
287
Given a binary search tree (BST), find the lowest common ancestor (LCA) of two given nodes in the BST.According to thedefinition of LCA on Wikipedia: ...
分类:
其他好文 时间:
2015-10-08 23:11:00
阅读次数:
224
题意比较费劲:输入看起来很麻烦。处理括号冒号的时候是用%1s就可以。还有就是注意它有根节点。。。Q次查询,我是用在线st做的。/************************************************************************* > File Na...
分类:
其他好文 时间:
2015-10-08 21:19:35
阅读次数:
122
题目传送门题意:先给一棵树,然后有一条额外的边,问u走到v从现在最短的路走和原来不加边走的路节省了多少距离分析:首先跑不加边的树的LCA,这样能求出任意两点的距离,那么现在x和y多连了一条边,如果能节省路程那一定是走了xy这条边,那么暴力枚举组合,比如求u到v,新边xy,ans = min (ans...
分类:
其他好文 时间:
2015-10-08 18:20:28
阅读次数:
183
LCA,全称为Lowest Common Ancestor, 即最近公共祖先。这是对于有根树而言的,两个节点u, v的公共祖先中距离最近的那个被称为最近公共祖先(这解释。。真通俗。。。)我们来看个图:4和7的LCA是2,5和6的LCA是1,2和5的LCA是2。最笨的实现方法就是;对于同一深度的点,一...
分类:
其他好文 时间:
2015-10-07 22:56:59
阅读次数:
265
Given a binary tree, find the lowest common ancestor (LCA) of two given nodes in the tree.According to thedefinition of LCA on Wikipedia: “The lowest ...
分类:
其他好文 时间:
2015-10-07 22:54:40
阅读次数:
200
题目传送门题意:一棵有向的树,问u到v是否可达分析:假设是无向树,DFS时正向的权值+1,反向的权值-1,然后找到LCA后判断dep数组和d数组就可以了/************************************************* Author :Running_...
分类:
其他好文 时间:
2015-10-06 18:09:03
阅读次数:
240
题目传送门题意:两种操作,问u到v的距离,并且u走到了v;把第i条边距离改成w分析:根据DFS访问顺序,将树处理成链状的,那么回边处理成负权值,那么LCA加上BIT能够知道u到v的距离,BIT存储每条边的信息,这样第二种操作也能用BIT快速解决利用RMQ的写法不知哪里写挫了,改用倍增法/******...
分类:
编程语言 时间:
2015-10-06 18:03:37
阅读次数:
276