随笔分类 - 数据结构
摘要:题:https://ac.nowcoder.com/acm/contest/7831/H 题意:给定n个点的树,每个节点都有颜色; 询问[Q,y]:求把所有y颜色的节点联通起来用的最少的边数。 更新[U,x,y]:将x节点的颜色改为y; 分析: 对于询问,我们可以假象为有俩个点作为总边,剩余颜色的点
阅读全文
摘要:题:https://ac.nowcoder.com/acm/contest/5278/G 题意:给定n个点的树,每个节点有权值,每个节点的权值每时刻都会向上移动一个高度,当节点的权值大于1时,这个节点就会在此节点上权值减少一,直至移动到树根,把最后的权值加到答案里去,最后问这个答案总和是多少? 分析
阅读全文
摘要:题:https://www.luogu.com.cn/problem/P3144 题意:给出n个点m条边的图,逐一删除每个指定点,问每次删除前图是否连通。 分析:把指定的序列反过来做就行,对于每个加进来的点,看原本集合中有无进来点的连边,有就用并查集联系起来,表示俩者所处连通块连通,(正着切断,反着
阅读全文
摘要:题:https://codeforces.com/contest/1304/problem/E 题意:给定一颗树,边权为1,m次询问,每次询问给定x,y,a,b,k,问能否在原树上添加x到y的边,a到b的路径长度等于k,注意这里的点和边都是可以重复走的; 分析:注意到点边可以重复走,我们就可以推出一
阅读全文
摘要:这是对点权计算的板子 #include<bits/stdc++.h> using namespace std; #define lson root<<1,l,midd #define rson root<<1|1,midd+1,r #define pb push_back typedef long
阅读全文
摘要:题:https://codeforces.com/contest/1249/problem/F 题意:给一颗树,边权为1,节点有点权,问取到一个点集,俩俩之间路径超过k,是点权和最大 思路:贪心地取点,先将点按照深度经行排序,每一次,取一个点权大于0的点,然后对于这个点bfs出去的路径小于k的点减去
阅读全文
摘要:题:https://www.cometoj.com/problem/1046 #include<bits/stdc++.h> using namespace std; typedef long long ll; struct node{ int id,daoda,xiaohao,val; bool
阅读全文
摘要:题:https://www.cometoj.com/problem/0221 #include<iostream> #include<cstring> #include<algorithm> #include<cstdio> #include<queue> using namespace std;
阅读全文
摘要:http://codevs.cn/problem/2370/ #include<bits/stdc++.h> using namespace std; const int M=5e4+5; const int N=20; struct node{ int v,w; node(int vv=0,int
阅读全文
摘要:#include<bits/stdc++.h> using namespace std; const int M=3e5+5; struct node{ int l,r,cnt,lazy; node(int l1=0,int r1=0,int cnt1=0,int lazy1=0):l(l1),r(
阅读全文
摘要:https://acm.ecnu.edu.cn/contest/173/problem/E/ 区间操作,线段树; 维护乘的次数和除的次数 最后答案是,div和mul共同作用的结果, 分两种来考虑,第一种是当前有足够多次1操作,所以当再来一次操作时,直接在此基础上进行修改,除就减,乘就加; 第二种比较
阅读全文
摘要:树的直径: 利用了树的直径的一个性质:距某个点最远的叶子节点一定是树的某一条直径的端点。 先从任意一顶点a出发,bfs找到离它最远的一个叶子顶点b,然后再从b出发bfs找到离b最远的顶点c,那么b和c之间的距离就是树的直径。 用dfs也可以。 http://poj.org/problem?id=19
阅读全文
摘要:http://poj.org/problem?id=1986 离线找u,v之间的最小距离(理解推荐) #include<iostream> #include<cstring> #include<cstdio> #include<algorithm> using namespace std; char
阅读全文

浙公网安备 33010602011771号