题目链接: http://poj.org/problem?id=1330 题意: 给你一颗有根树,最后输入一对数(a,b),叫你求a和b的公共祖先。 裸的lca,数据也很小,拿来练手不错。 题解: 1、tarjan_lca,离线,线性时间复杂度 代码: 1 #include<iostream> 2 ...
分类:
其他好文 时间:
2016-04-13 01:56:46
阅读次数:
148
题目链接: Distance Queries Time Limit: 2000MS Memory Limit: 30000K Total Submissions: 11531 Accepted: 4068 Case Time Limit: 1000MS Description Farmer John ...
分类:
其他好文 时间:
2016-04-11 20:20:51
阅读次数:
251
题目:http://www.tsinsen.com/A1505 A1505. 树(张闻涛) 时间限制:1.0s 内存限制:512.0MB 总提交次数:196 AC次数:65 平均分:58.62 时间限制:1.0s 内存限制:512.0MB 总提交次数:196 AC次数:65 平均分:58.62 将本 ...
分类:
其他好文 时间:
2016-04-11 00:14:31
阅读次数:
285
Description 小机房有棵焕狗种的树,树上有N个节点,节点标号为0到N-1,有两只虫子名叫飘狗和大吉狗,分居在两个不同的节点上。有一天,他们想爬到一个节点上去搞基,但是作为两只虫子,他们不想花费太多精力。 已知从某个节点爬到其父亲节点要花费 c 的能量(从父亲节点爬到此节点也相同),他们想找 ...
分类:
其他好文 时间:
2016-04-11 00:08:05
阅读次数:
182
题目链接: Connections between cities Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Problem Description After World War ...
分类:
其他好文 时间:
2016-04-10 23:55:31
阅读次数:
365
题目链接: How far away ? Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Problem Description There are n houses in the vi ...
分类:
其他好文 时间:
2016-04-10 17:37:49
阅读次数:
178
Connections between cities Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 8041 Accepted Submiss ...
分类:
其他好文 时间:
2016-04-08 19:48:37
阅读次数:
227
Given a binary search tree (BST), find the lowest common ancestor (LCA) of two given nodes in the BST. According to the definition of LCA on Wikipedia ...
分类:
其他好文 时间:
2016-04-08 19:33:34
阅读次数:
150
POJ - 1330 Nearest Common Ancestors(dfs+ST在线算法|LCA倍增法) d.输入树中的节点数N,输入树中的N-1条边。最后输入2个点,输出它们的最近公共祖先。 s.裸的最近公共祖先。 c.dfs+ST在线算法: /* LCA(POJ 1330) 在线算法 DFS ...
分类:
其他好文 时间:
2016-04-08 11:49:46
阅读次数:
191
学习了树上莫队,树分块后对讯问的$dfs序$排序,然后就可以滑动树链处理答案了。 关于树链的滑动,只需要特殊处理一下$LCA$就行了。 在这里一条树链保留下来给后面的链来转移的$now$的为这条树链上所有点除去$LCA$的颜色种数。因为如果要考虑$LCA$情况就太多了,不如单独考虑$LCA$。 转移 ...
分类:
移动开发 时间:
2016-04-07 22:09:21
阅读次数:
369