HDU 4679 Terrorist’s destroy】的更多相关文章

Terrorist’s destroy Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others)Total Submission(s): 24    Accepted Submission(s): 6 Problem Description There is a city which is built like a tree.A terrorist wants to destroy th…
链接:http://acm.hdu.edu.cn/showproblem.php?pid=4679 题意:给定一颗树,每条边有一个权值w,问切掉哪条边之后,分成的两颗树的较大的直径*切掉边的权值最小?如果存在多条边使得结果相同,输出边id最小的 思路: dept一次找出最深的节点,之后以最深的节点出发(rt1)dept找到树的直径(即找到rt2):将路径保存在f[]中: 之后分别从rt1/rt2进行深搜,找到以一个节点为根的树的直径,这样在每次dfs之后,可以求出每条边的一边的最值,这样两次取m…
如果不在最长路的边,那么肯定是w*最长路. 如果在最长路,那么把最长路分成两段,左边树的最长路就是左段+左边点的次短路(不包含最长路上的点的最长路) ,右边同理. 还有就是更新,经过左端点的最长路,不一定是整颗左边树的最长路,乱搞一下就可以了.我是搞成一条链,写的很麻烦..从一点搞到了快四点.. #include <iostream> #include <cstdio> #include <cstring> #include <cmath> #include…
题意:给你一棵树,每条边都有值W,然后问你去掉一条边,令val = w*max(两颗新树的直径),求val最小值~ 做法,先求树的直径,然后算出直径上每个点的最长枝条长度.这样对于每一条边,假如是枝条边,那么val = w*直径,如果不是那么val = max(w*(两颗新树的直径)).新树直径说到这里已经很好算了. DFS爆栈了一下午 #include <stdio.h> #include <string.h> #include <iostream> #include…
Terrorist’s destroy HDU - 4679 There is a city which is built like a tree.A terrorist wants to destroy the city's roads. But now he is alone, he can only destroy one road, then the city will be divided into two cities. Impression of the city is a num…
题意: There is a city which is built like a tree.A terrorist wants to destroy the city's roads. But now he is alone, he can only destroy one road, then the city will be divided into two cities. Impression of the city is a number defined as the distance…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4679 题意:给一颗树,每个边有一个权值,要你去掉一条边权值w剩下的两颗子树中分别的最长链a,b,使得w*Min(a,b)最小.. 说白了就是要枚举每条边,然后在O(1)的时间内求出两颗子树的最长链.因此我们可以考虑用树形DP,首先一遍DFS,对于每个节点维护两个信息,hign[u]:u为根节点的子树的深度,f[u]:u为根节点的子树的最长链.然后还要维护一个hige[i][0]和hige[i][1]…
思路:我们其实只需要枚举每条边,求得最小值就行了. 先dfs算出每个节点作为根时,其子树的最长路径,以及进过该节点的最长,次长,第三长路径. 然后在次dfs枚举求出切断某条边,求出这条边的两个端点为子树根,其子树的最长路径.b就是其中较大的. #pragma comment(linker, "/STACK:1024000000,1024000000") #include<iostream> #include<cstring> #include<algori…
题意:给一棵树,边的权值都是1,摧毁每条边是有代价的,选择摧毁一条边,把一棵树分成两部分,求出两部分中距离最大的两点的距离,求出距离*代价最小的边,多条的话输出序号最小的. 刚开始理解错题意了,wrong了几次,一直在纠结摧毁一条边后上边的树的最远距离怎么求,儿子树的最远距离就是所有子树的最长边+次长边就可以了.当我们求到一个节点u时,肯定有一个祖先节点,该祖先节点在摧毁与u链接的边后剩余的子树中最长的边和次长边之和是最大的,如果摧毁u与子节点的边时,就要考虑那个祖先节点的位置了,可能就是u这个…
String Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others) Total Submission(s): 695    Accepted Submission(s): 254 Problem Description Given 3 strings A, B, C, find the longest string D which satisfy the following rule…