有点像计蒜之道里的 京东的物流路径 题目描述 给定一棵 N 个节点的树,每个节点有一个正整数权值.记节点 i 的权值为 Ai.考虑节点 u 和 v 之间的一条简单路径,记 dist(u, v) 为其长度,gcd(u, v) 为路径上所有节点(包含 u 和 v)的权值的最大公因子.min(u, v) 为路径上所有节点的权值的最小值.请求出所有节点对 (u, v) 中 dist(u, v) · gcd(u, v) · min(u, v) 的最大值 输入格式 输入的第一行包含一个整数 T,代表测试数据…
目录 题意 解析 AC_code @(Codechef March Cook-Off 2018. Maximum Tree Path) 题意 给你一颗\(n(1e5)\)个点有边权有点权的树,\(Min(u,v)\)表示\(u,v\)路径最小点权,\(gcd(u,v)\)表示\(u,v\)路径点权的最大公因数,\(dis(u,v)\)表示\(u,v\)路径大小. 输出\(max(dis(u,v)*gcd(u,v)*Min(u,v))\) 解析 法一: 外层枚举路径的gcd,并把两端点是gcd倍数…
6690: Transit Tree Path 时间限制: 1 Sec  内存限制: 128 MB提交: 472  解决: 132[提交] [状态] [讨论版] [命题人:admin] 题目描述 You are given a tree with N vertices.Here, a tree is a kind of graph, and more specifically, a connected undirected graph with N−1 edges, where N is the…
Delay Constrained Maximum Capacity Path Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=1839 Description Consider an undirected graph with N vertices, numbered from 1 to N, and M edges. The vertex numbered with…
问题 D: Transit Tree Path   You are given a tree with N vertices.Here, a tree is a kind of graph, and more specifically, a connected undirected graph with N−1 edges, where N is the number of its vertices.The i-th edge (1≤i≤N−1) connects Vertices ai and…
376. Binary Tree Path Sum Given a binary tree, find all paths that sum of the nodes in the path equals to a given number target. A valid path is from root node to any of the leaf nodes. Example Example 1: Input: {1,2,4,2,3} 5 Output: [[1, 2, 2],[1, 4…
Delay Constrained Maximum Capacity Path Time Limit: 10000/10000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/Others)Total Submission(s): 1790    Accepted Submission(s): 577 Problem Description Consider an undirected graph with N vertices, nu…
地址https://www.codechef.com/LTIME58B?order=desc&sortBy=successful_submissions 简单做了一下,前三题比较水,第四题应该算是经典题 AChef and Friends 直接暴力枚举即可 #include<cstdio> #include<cstring> #include<algorithm> using namespace std; , INF = 1e9 + ; inline int r…
Problem 1 [Balanced Binary Tree] Given a binary tree, determine if it is height-balanced. For this problem, a height-balanced binary tree is defined as a binary tree in which the depth of the two subtrees of every node never differ by more than 1. Pr…
The Street Problem Code: STREETTA https://www.codechef.com/problems/STREETTA Submit Tweet All submissions for this problem are available. Read problems statements in Mandarin Chineseand Russian. The String street is known as the busiest street in Cod…
Given a binary tree, find all paths that sum of the nodes in the path equals to a given number target. A valid path is from root node to any of the leaf nodes. Example Given a binary tree, and target = 5: 1 / \ 2 4 / \ 2 3 return [ [1, 2, 2], [1, 4]…
思路: 简单搜索 总结: dfs 框架 1. 需要打印路径. 在 dfs 函数中假如 vector 变量, 不用 & 修饰的话就不需要 undo 2. 不需要打印路径, 可设置全局变量 ans, 在 dfs 函数中对 ans 判定, 判定的位置尽可能的多 3. 对 tree 遍历, 有两种办法, 第一种是 if(root == NULL) 第二种是 if(root->left == NULL), 我一般用第二种, 效率比较高, 但是在第二种 return 1, 第一种 return 0 4.…
Description Given a binary tree, find all paths that sum of the nodes in the path equals to a given number target. A valid path is from root node to any of the leaf nodes. Example Given a binary tree, and target = 5: 1 / \ 2 4 / \ 2 3 return [ [1, 2,…
传送门:http://abc070.contest.atcoder.jp/tasks/abc070_d 本题是一个图论问题——树(Tree). 有一棵结点数目为n的无向树.第i条边连接结点ai与bi,权值为ci.给出q次查询,以及一个整数k(1≤k≤n),第j次查询给出两个整数xj,yj(1≤xj,yj≤n),求解结点xj和yj通过结点k的最短路径长度. 树上的路径问题,可以通过DFS解决.以下代码片段计算结点间的路径长度dis. void dfs(int v) { vis[v] = true;…
最短路+二分. 对容量进行二分,因为容量和时间是单调关系的,容量越多,能用的边越少,时间会不变或者增加. 因为直接暴力一个一个容量去算会TLE,所以采用二分. #include<cstdio> #include<vector> #include<cstring> #include<queue> #include<map> #include<algorithm> using namespace std; ; const int INF…
题意:n个点,n-1条边,组成一个无向的联通图,然后给出q和k,q次询问,每次给出两个点,问这两个点之间的最短距离但必须经过k点. 思路:我当时是用优化的Dijkstra写的(当天刚学的),求出k点到各点的最短距离,跑了160+ms,其实用搜索写更快,组里的几个大佬都用搜索写的,我在搜索这方面还是比较弱的.还要多练练.然后今天早上用搜索写了一下,跑了60+ms,并且内存用的也很小. 题目链接:http://abc070.contest.atcoder.jp/tasks/abc070_d Dijk…
PSHTTR: Pishty 和城堡题目描述Pishty 是生活在胡斯特市的一个小男孩.胡斯特是胡克兰境内的一个古城,以其中世纪风格的古堡和非常聪明的熊闻名全国.胡斯特的镇城之宝是就是这么一座古堡,历史上胡斯特依靠这座古堡抵挡住了疯人国的大军.对于 Pishty 来说,真正吸引他的是古堡悠长的走廊和高耸的钟楼,以及深藏于其中的秘密……古堡可以用一棵 N 个节点的树的描述,树中有 N − 1 条无向边,每条边有一个魔法数字 C.当一个旅游团参观古堡时,他们会选择树上 U 到 V 的路径游览.他们认…
传送门 \(CHNUM\) 显然正数一组,负数一组 for(int T=read();T;--T){ n=read(),c=d=0; fp(i,1,n)x=read(),x>0?++c:++d; if(!c)c=d;if(!d)d=c; if(c<d)c^=d^=c^=d; printf("%d %d\n",c,d); } \(CHDIGER\) 从原来的数列中选出字典序最小的上升子序列,往后面加\(d\)就行了 //minamoto #include<bits/st…
The Street 思路: 动态开节点线段树: 等差序列求和于取大,是两个独立的子问题: 所以,建两颗线段树分开维护: 求和:等差数列的首项和公差直接相加即可: 取大: 对于线段树每个节点储存一条斜率为等差数列公差的线段: 当添加线段到已有线段的节点,下传一条线段,当前节点留下一条线段: 当要添加的线段完全覆盖或者被覆盖当前节点储存的线段时,选择更新或者不更新: 单点查询时,从根节点到叶节点的路径上去最大值: 来,上代码: #include <cstdio> #include <cst…
题意: 一棵n个节点的树,节点有黑白两种颜色,初始均为白色.两种操作:1.更改一个节点的颜色;2.询问一个节点所处的颜色相同的联通块的大小. 思路: 1.每个节点记录仅考虑其子树时,假设其为黑色时所处的黑色联通块的大小和假设其为白色时所处的白色联通块的大小(树状数组维护). 2.查询时找到深度最小的.与该点颜色相同的且两点之间的点颜色均与这两点相同(两点可以重合)(不妨称它为最远祖先)的答案. 3.修改时应该修改该节点的父亲至最远祖先的父亲上的值. 4.用树链剖分和树状数组维护. 5.寻找最远祖…
一般xor 的题目都是用trie解决. 那这道题是在树上的trie; 首先:从root==1,遍历树得到1到所有节点的xor 值. 然后对于每个点我们把其插入二进制树中. 对于每一个点查找其二进值异或值最大的数 依次遍历下来. 注意:边的数量开两倍以上,RE很多次. find函数具体是这样的: 对于一个书二进值:10001000101 #include<iostream> #include<cstdio> #include<algorithm> #include<…
考的这么差二试基本不用去了 不想说什么了.就把这几天听课乱记的东西丢上来吧 这里是二试乱听课笔记ZJOI2019Round#2 ZJOI Round#1 Day1 M.<具体数学>选讲 罗煜翔-宁波市镇海中学 上升/下降阶乘幂 差分和和式 差分类似求导:和式类似积分 下降幂多项式与下降幂级数 考虑如何计算两个下降幂多项式的乘积 如何处理下降幂多项式的点值? 下降幂级数在自然数处收敛,在其他数位置基本不收敛 点值的数量大概是阶乘级别的,考虑点值的指数生成函数 那么我们选取自然数生成点值.关于点值…
Problem Link: http://oj.leetcode.com/problems/binary-tree-maximum-path-sum/ For any path P in a binary tree, there must exists a node N in P such that N is the ancestor node of all other nodes in P. We call such N as the root of P, or P roots at N. T…
Home » Practice(Hard) » Observing the Tree   https://www.codechef.com/problems/QUERY Observing the Tree Problem Code: QUERY Submit Tweet All submissions for this problem are available. Chef gives you a tree, consisting of N nodes. The nodes are numbe…
题目如下: We are given the root node of a maximum tree: a tree where every node has a value greater than any other value in its subtree. Just as in the previous problem, the given tree was constructed from an list A (root = Construct(A)) recursively with…
作者: 负雪明烛 id: fuxuemingzhu 个人博客:http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 递归 日期 题目地址:https://leetcode.com/problems/maximum-binary-tree/description/ 题目描述 Given an integer array with no duplicates. A maximum tree building on this array is defined as fol…
Given an integer array with no duplicates. A maximum tree building on this array is defined as follow: The root is the maximum number in the array. The left subtree is the maximum tree constructed from left part subarray divided by the maximum number…
Given an integer array with no duplicates. A maximum tree building on this array is defined as follow: The root is the maximum number in the array. The left subtree is the maximum tree constructed from left part subarray divided by the maximum number…
Given an integer array with no duplicates. A maximum tree building on this array is defined as follow: The root is the maximum number in the array. The left subtree is the maximum tree constructed from left part subarray divided by the maximum number…
We are given the root node of a maximum tree: a tree where every node has a value greater than any other value in its subtree. Just as in the previous problem, the given tree was constructed from an list A (root = Construct(A)) recursively with the f…