树形结构
hehedad
这个作者很懒,什么都没留下…
展开
-
2020牛客暑期多校训练营(第五场)B Graph
根据题目描述我们可以知道,无论添加的时间顺序,添加a-b的边的大小一定是固定的,即a-b上的路径上的所有长度的异或,所以题目就可以简化成寻找完全图的最小生成树。 设dis[n]为0-n点的链路上所有边长的的异或,则在之前所说的完全图中,a-b的边长就是dis[a] ^ dis[b],即为a-b上的路径上的所有长度的异或(假设最小公共祖先为c,dis[a]^dis[b]中有两段多余的0-c的异或会被相互中和掉)。则相当于每个点有一个值dis[n],而两点之间边长即为dia[a]^dis[b]...原创 2020-07-25 17:41:25 · 1680 阅读 · 7 评论 -
SPOJ - QTREE Query on a tree 树链剖分+线段树形式
You are given a tree (an acyclic undirected connected graph) with N nodes, and edges numbered 1, 2, 3...N-1.We will ask you to perfrom some instructions of the following form:CHANGE i ti : change ...原创 2019-02-17 16:15:51 · 148 阅读 · 0 评论 -
POJ - 2763 Housewife Wind (树链剖分+线段树+边权)
After their royal wedding, Jiajia and Wind hid away in XX Village, to enjoy their ordinary happy life. People in XX Village lived in beautiful huts. There are some pairs of huts connected by bidirecti...原创 2019-02-17 18:21:34 · 158 阅读 · 0 评论 -
Tree POJ - 3237(树链剖分+线段树(懒惰标记))
You are given a tree with N nodes. The tree’s nodes are numbered 1 through N and its edges are numbered 1 through N − 1. Each edge is associated with a weight. Then you are to execute a series of inst...原创 2019-02-18 01:48:04 · 194 阅读 · 0 评论 -
HDU - 4417 Super Mario (划分树+二分)
Mario is world-famous plumber. His “burly” figure and amazing jumping ability reminded in our memory. Now the poor princess is in trouble again and Mario needs to save his lover. We regard the road to...原创 2019-03-11 20:38:10 · 126 阅读 · 0 评论 -
HDU - 3473 Minimum Sum (划分树,额外处理获得区间小(大)于第k数的和)
You are given N positive integers, denoted as x0, x1 ... xN-1. Then give you some intervals [l, r]. For each interval, you need to find a number x to makeas small as possible!InputThe first line ...原创 2019-03-11 20:40:21 · 121 阅读 · 0 评论 -
POJ - 3177 Redundant Paths (边双连通||无向图缩点)
In order to get from one of the F (1 <= F <= 5,000) grazing fields (which are numbered 1..F) to another field, Bessie and the rest of the herd are forced to cross near the Tree of Rotten Apples....原创 2019-04-15 21:55:03 · 208 阅读 · 0 评论 -
2019 ICPC南昌邀请赛比赛 J Distance on the tree(树链剖分上建可持续化线段树)
DSM(Data Structure Master) once learned about tree when he was preparing for NOIP(National Olympiad in Informatics in Provinces) in Senior High School. So when in Data Structure Class in College, he i...原创 2019-04-22 21:16:21 · 1135 阅读 · 2 评论 -
ZOJ - 3195 Design the city (树上多点间最短路径)
Cerror is the mayor of city HangZhou. As you may know, the traffic system of this city is so terrible, that there are traffic jams everywhere. Now, Cerror finds out that the main reason of them is the...原创 2019-04-24 18:53:55 · 446 阅读 · 0 评论 -
ZOJ - 4097 Rescue the Princess (边双联通缩点无向图+思维lca)
Rescue the PrincessPrincess Cjb is caught by Heltion again! Her knights Little Sub and Little Potato are going to H...原创 2019-04-20 00:56:06 · 271 阅读 · 0 评论 -
ZOJ - 3602 Count the Trees 二叉树同构
A binary tree is a tree data structure in which each node has at most two child nodes, usually distinguished as "left" and "right". A subtree of a tree T is a tree consisting of a node in T and all of...原创 2019-05-04 23:56:25 · 126 阅读 · 0 评论 -
GCD Problem (线段树区间GCD+区间开方)
题目描述输入描述:输出描述:输入45 45 20 6571 1 40 1 41 1 41 3 40 3 41 3 41 2 2输出52426 两个操作,一个是区间开方,一个是输出区间GCD;gcd很好处理。主要是开放这个操作,假设区间sum==l-r+1就return,不是的话就取找辣个还不是1的点去单点更新,这样...原创 2019-04-25 18:21:25 · 345 阅读 · 0 评论 -
CodeForces - 76A Gift (两个取值方向的最小生成树)
gThe kingdom of Olympia consists ofNcities andMbidirectional roads. Each road connects exactly two cities and two cities can be connected with more than one road. Also it possible that some roads ...原创 2019-06-05 21:06:01 · 319 阅读 · 0 评论 -
C Just h-index
链接:https://ac.nowcoder.com/acm/contest/1107/C来源:牛客网时间限制:C/C++ 1秒,其他语言2秒空间限制:C/C++ 131072K,其他语言262144KSpecial Judge, 64bit IO Format: %lld题目描述The h-index of an author is the largest h where ...原创 2019-10-02 17:37:55 · 12878 阅读 · 0 评论 -
Highway (树的直径 + dfs)
链接:https://ac.nowcoder.com/acm/contest/1109/H来源:牛客网时间限制:C/C++ 3秒,其他语言6秒空间限制:C/C++ 32768K,其他语言65536KSpecial Judge, 64bit IO Format: %lld题目描述In ICPCCamp there were n towns conveniently number...原创 2019-10-04 16:10:17 · 301 阅读 · 0 评论 -
HDU - 3966 Aragorn's Story(树链剖分,树状数组模式)
Our protagonist is the handsome human prince Aragorn comes from The Lord of the Rings. One day Aragorn finds a lot of enemies who want to invade his kingdom. As Aragorn knows, the enemy has N camps ou...原创 2019-02-15 15:53:44 · 165 阅读 · 0 评论 -
洛谷 P3128 [USACO15DEC]最大流Max Flow(树上差分~~)
Farmer John has installed a new system of N-1 pipes to transport milk between the N stalls in his barn (2≤N≤50,000), conveniently numbered 1 \ldots N1…N. Each pipe connects a pair of stalls, and all s...原创 2018-12-09 20:57:52 · 166 阅读 · 1 评论 -
ZOJ - 1610 Count the Colors(以区间为”点“的线段树)
Count the Colors Time Limit: 2 Seconds Memory Limit: 65536 KB Painting some colored segments on a line, some previously painted segments may be covered by some the subsequent ones....原创 2018-07-24 20:41:26 · 165 阅读 · 0 评论 -
我自己的小小线段树模板
#include<iostream>#include<cstdio>using namespace std;#define maxn 100005#define mid m=(l+r)>>1#define lson l,m,rt<<1#define rson m+1,r,rt<<1|1int c[maxn <<...原创 2018-07-25 20:11:17 · 167 阅读 · 3 评论 -
我用的小小的次小生成树模板
次小生成树的生成分为两种,一种是带重边的,一种是不带重边的~~;首先是不带重边的,就可以用prim来做#include<iostream>#include<cstdio>#include<algorithm>using namespace std;const int inf = 0x3f3f3f3f;const int maxn = 105;...原创 2018-07-26 10:44:28 · 234 阅读 · 0 评论 -
POJ - 1679 The Unique MST(次小生成树)
The Unique MSTTime Limit: 1000MS Memory Limit: 10000K Total Submissions: 35193 Accepted: 12860 DescriptionGiven a connected undirected graph, tell if its minimum spanning tree ...原创 2018-07-26 14:06:21 · 102 阅读 · 0 评论 -
HDU - 6315 Naive Operations
Naive Operations Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 502768/502768 K (Java/Others) Total Submission(s): 2498 Accepted Submission(s): 1096 Problem Description...原创 2018-07-29 19:55:14 · 187 阅读 · 0 评论 -
HDU - 2121 Ice_cream’s world II (不定根树形图)
Ice_cream’s world II Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 6367 Accepted Submission(s): 1658 Problem Description...原创 2018-07-30 10:03:46 · 222 阅读 · 0 评论 -
HDU - 4009 Transfer water (最小树形图)
Transfer water Time Limit: 5000/3000 MS (Java/Others) Memory Limit: 65768/65768 K (Java/Others) Total Submission(s): 5902 Accepted Submission(s): 2098 Problem Description X...原创 2018-07-30 16:25:45 · 152 阅读 · 0 评论 -
矩阵树定理 Matrix Tree(看见大佬总结忍不住转载)
矩阵树定理 Matrix Tree 矩阵树定理主要用于图的生成树计数。 看到给出图求生成树的这类问题就大概要往这方面想了。 算法会根据图构造出一个特殊的基尔霍夫矩阵AA,接着根据矩阵树定理,用AA计算出生成树个数。 1.无向图的生成树计数 对于给定的可含重边的连通无向图GG,求其生成树的个数。求法如下: 定义度数矩阵DD:...转载 2018-07-30 16:50:43 · 2067 阅读 · 1 评论 -
关于生成树计数问题和多种情况
大的道理和理论我就不说了,有什么理论上的疑惑我推荐下这个地址: https://blog.csdn.net/u013010295/article/details/47451451 一:无向图中的生成树计数; 这种情况下我们要看看是否存在重边的情况,如果没有的话就可以用Matrix-Tree定理和高斯消元直接来解; ...原创 2018-07-31 11:08:21 · 822 阅读 · 0 评论 -
我的最小树形图板子
#include<iostream>#include<cstdio>#include<cstring>using namespace std;#define inf 0x3f3f3f3fint n, m;struct fuck{ int from, to, len;}ed[1000005];int id[1005];int pre[100...原创 2018-07-27 19:05:20 · 212 阅读 · 0 评论 -
CodeForces 967F. Aztec Catacombs(思维建树图)
F. Aztec Catacombstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputIndiana Jones found ancient Aztec catacombs containing a golde...原创 2018-08-03 14:12:50 · 248 阅读 · 0 评论 -
POJ - 1741 Tree (点分治)
TreeTime Limit:1000MS Memory Limit:30000K Total Submissions:29895 Accepted:10019 DescriptionGive a tree with n vertices,each edge has a length(positive integer less than 10...原创 2018-09-07 23:07:20 · 140 阅读 · 0 评论 -
HDU - 2196 Computer (树的直径)
Computer Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 33989 Accepted Submission(s): 5236 Problem Description A schoo...原创 2018-09-05 19:41:04 · 260 阅读 · 0 评论 -
树上差分(顺便%%%大佬)
一、差分 有这样一道题目:给你一个m×nm×n的矩阵,然后使用kk块地毯铺地。每片地毯都给出左下角和右上角坐标。问所有地毯铺完之后,还有多少个整点(所谓整点,即横、纵坐标均为整数的点)没有被地毯覆盖。 当然,我们很容易写出如下的暴力程序(伪代码): 1 2 3 4 5 solve(){ 暴力枚举每张地毯...转载 2018-12-09 19:37:15 · 223 阅读 · 0 评论 -
HDU - 1698 Just a Hook(线段树区间更新区间查找)
Just a Hook Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 41024 Accepted Submission(s): 19780 Problem Description In ...原创 2018-07-24 16:25:00 · 180 阅读 · 0 评论