
最近公共祖先【LCA】
poursoul
这个作者很懒,什么都没留下…
展开
-
【HDU】2460 Network 双连通+LCA变形
NetworkTime Limit: 10000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 749 Accepted Submission(s): 149Problem DescriptionA network administr原创 2014-07-14 22:15:51 · 929 阅读 · 0 评论 -
【HDU】5796 Magic Number【lca】
题目链接:Magic Number看懂题目,就知道怎么做#include <stdio.h>#include <vector>#include <string.h>#include <algorithm>using namespace std ;typedef long long LL ;typedef pair < int , int > pii ;#define clr( a , x原创 2016-10-08 12:38:35 · 530 阅读 · 0 评论 -
【HDU】5574 Colorful Tree【子树染色,询问子树颜色数——线段树+bit+lca+set】
题目链接:【HDU】5574 Colorful Tree#include <bits/stdc++.h>using namespace std ;typedef long long LL ;typedef pair < int , int > pii ;#define clr( a , x ) memset ( a , x , sizeof a )const int MAXN = 100005原创 2016-11-01 11:19:28 · 2500 阅读 · 0 评论 -
【HDU】5293 Tree chain problem【DP+LCA】
传送门:【HDU】5293 Tree chain problemmy code:my~~code:/************************************************************************* > File Name: F.cpp > Author: poursoul > Created Time: 2015年07月22原创 2015-07-27 15:48:50 · 670 阅读 · 0 评论 -
【HDU】5156 Harry and Christmas tree 【lca】
传送门:【HDU】5156 Harry and Christmas tree题目分析:每一种颜色我们分开考虑他们对所有节点的贡献,对于两个颜色同为c的节点u和v(假设u!=v),那么在lca(u,v)的时候我们需要-1,因为在lca(u,v)一直到根的路径上,颜色c只能影响一次。基于此,我们对每种颜色的所有节点按照dfs序排好序,首先每个节点+1,然后对dfs序相邻的两个节点(注意颜色原创 2015-01-04 19:20:58 · 885 阅读 · 0 评论 -
【codeforces】494D. Birthday 【树型DP+离线tarjan求LCA】
传送门:【codeforces】494D. Birthday题目分析:首先明确一点,平方和是可以递推的!1.我们第一次dfs,求出从一个点到其子树的所有点的距离的平方和。大体是保存三个变量来递推,设u的子树上点的个数cnt,到子树上点的距离和sum,到子树上点的距离平方和sqr,每次dfs完一个儿子v以后:dp[u].cnt+=dp[v].cntdp[u].sum+=d原创 2014-12-14 14:21:37 · 1278 阅读 · 0 评论 -
【HDU】3686 Traffic Real Time Query System 点双连通+LCA
传送门:【HDU】3686 Traffic Real Time Query System原创 2014-11-22 14:37:59 · 1788 阅读 · 0 评论 -
【HDU】4912 Paths on the tree 离线LCA+贪心
传送门:【HDU】4912 Paths on the tree【HDU】4912 Paths on the tree原创 2014-11-14 09:40:17 · 1097 阅读 · 0 评论 -
【CodeForces】406D Hill Climbing 单调栈建树+树链剖分求LCA
传送门:【CodeForces】406D Hill Climbing原创 2014-09-28 18:49:26 · 1271 阅读 · 0 评论 -
【SPOJ】913 Query on a tree II QTREE系列之2【LCA】
传送门:【SPOJ】913 Query on a tree II题目分析:原创 2014-09-15 19:47:17 · 1194 阅读 · 0 评论 -
【HDU】2874 Connections between cities 离线LCA
Connections between citiesTime Limit: 10000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 4304 Accepted Submission(s): 1236Problem DescriptionAf原创 2014-07-07 19:42:59 · 1208 阅读 · 0 评论 -
【POJ】 1986 Distance Queries 离线LCA
Distance QueriesTime Limit: 2000MS Memory Limit: 30000KTotal Submissions: 8694 Accepted: 3052Case Time Limit: 1000MSDescriptionFarmer John's cows refused to r原创 2014-07-03 19:16:27 · 1200 阅读 · 0 评论 -
【HDU】2586 How far away ? LCA求树上点对最近距离
How far away ?Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 4702 Accepted Submission(s): 1765Problem DescriptionThere are n hou原创 2014-07-02 22:13:37 · 1544 阅读 · 0 评论 -
【POJ】1330 Nearest Common Ancestors 在线LCA,倍增思想
Nearest Common AncestorsTime Limit: 1000MS Memory Limit: 10000KTotal Submissions: 17144 Accepted: 9128DescriptionA rooted tree is a well-known data structure in com原创 2014-07-02 21:23:39 · 1048 阅读 · 0 评论 -
【HDU】5759 Gardener Bo【线段树+lca+分类讨论】
题目链接:Gardener Bo分情况处理add操作即可。#include <stdio.h>#include <string.h>#include <math.h>#include <vector>#include <algorithm>using namespace std ;typedef unsigned int UI ;typedef pair < int , int > pi原创 2016-10-08 13:05:06 · 480 阅读 · 0 评论