题目链接 Paths on the tree 来源 2014 多校联合训练第5场 Problem B 题意就是给出m条树上的路径,让你求出可以同时选择的互不相交的路径最大数目. 我们先求出每一条路径(u, v)中u和v的LCA:w,按照路径的w的深度大小deep[w]对所有的路径排序. deep[w]越大,排在越前面. 然后从第一条路径开始一次处理,看c[u]和c[v]是否都没被标记过,如果都没被标记过则我们把这条路径选上,把答案加1. 同时标记以w为根的子树的节点为1,方便后续对c数组的查询…
先给个LCA模板 HDU 1330(LCA模板) #include <cstdio> #include <cstring> #define N 40005 struct Edge{ int x,y,d,ne; }; Edge e[N*],e2[N*]; int be[N],be2[N],all,all2,n,m; bool vis[N]; int fa[N]; ]; int dis[N]; void add(int x, int y, int d, Edge e[], int be…
Paths on the tree Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others) Total Submission(s): 297 Accepted Submission(s): 93 Problem Description bobo has a tree, whose vertices are conveniently labeled by 1,2,-,n. Th…
Dylans loves tree Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)Total Submission(s): 1444 Accepted Submission(s): 329 Problem Description Dylans is given a tree with N nodes. All nodes have a value A[i].Nodes…
F. Three Paths on a Tree time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output You are given an unweighted tree with nn vertices. Recall that a tree is a connected undirected graph without cycle…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5458 Problem Description Given an undirected connected graph G with n nodes and m edges, with possibly repeated edges and/or loops. The stability of connectedness between node u and node v is defined by…
题目链接: 题目 E. Paths and Trees time limit per test 3 seconds memory limit per test 256 megabytes inputstandard input outputstandard output 问题描述 Little girl Susie accidentally found her elder brother's notebook. She has many things to do, more important…
D. Arpa's letter-marked tree and Mehrdad's Dokhtar-kosh paths CF741D 题意: 一棵有根树,边上有字母a~v,求每个子树中最长的边,满足这个边上的所有字母重拍后可以构成回文 发明者自己出的题...orz 由于本来知道就是dsu on tree,所以还是想出来了 首先点分治是没法做了,这是有根树 写成二进制,两条链合起来构成回文\(\rightarrow\)异或和为0或者只有一位是1 一开始困惑于只处理到当前根的异或和的话,随着当前…
Annoying problem 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5296 Description Coco has a tree, whose nodes are conveniently labeled by 1,2,-,n, which has n-1 edge,each edge has a weight. An existing set S is initially empty. Now there are two kin…
题目链接:http://acm.split.hdu.edu.cn/showproblem.php?pid=5423 Problem Description As we know, Rikka is poor at math. Yuta is worrying about this situation, so he gives Rikka some math tasks to practice. There is one of them: For a tree T, let F(T,i) be t…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2586 题意:给出一棵n个节点的无根树,每条边有各自的权值.给出m个查询,对于每条查询返回节点u到v的最短路径的权值和,按查询顺序输出结果. 数据范围:n [2, 40000], m[1, 200] 思路:Tarjan算法:dfs遍历每个点,每遍历完 r 的一个孩子 c, 把 c 并入以 r 为祖先的集合,并处理 c 的所有查询 q:若qi的目标节点 v 已被遍历到,那么一定有lca(c, v) =…
Balala Power! Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)Total Submission(s): 2668 Accepted Submission(s): 562 Problem Description Sample Input 1 a 2 aa bb 3 a ba abc Sample Output Case #1: 25 Case #2: 132…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6203 题意:n+1 个点 n 条边的树(点标号 0 ~ n),有若干个点无法通行,导致 p 组 U V 无法连通.问无法通行的点最少有多少个. 解法:按照询问的LCA深度排序,然后顺序标记每个询问的LCA.根据所给的树(任意点为根)预处理出每个点的前序 DFS 序和后序 DFS 序(需统一标号),及点的深度.根据 p 组 U V 处理每组两点的 LCA .压入优先队列(LCA 深度大的点优先出队).…