HDOJ 2196 Computer 树的直径】的更多相关文章

由树的直径定义可得,树上随意一点到树的直径上的两个端点之中的一个的距离是最长的... 三遍BFS求树的直径并预处理距离....... Computer Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 3522    Accepted Submission(s): 1784 Problem Description A school bou…
Computer Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Problem Description A school bought the first computer some time ago(so this computer's id is 1). During the recent years the school bought N-1 new computers…
[HDU 2196] Computer(树的直径) 题链http://acm.hdu.edu.cn/showproblem.php?pid=2196 这题可以用树形DP解决,自然也可以用最直观的方法解,先求出树的直径,那么树的任意节点的最远点必然是直径上的两个端点之一,证明可以通过反证法构造: 设端点为a,b;设任意点为i,假设存在一点c到i的距离大鱼i到a,b的距离,那么a与c又能形成一个距离更长的点对,与ab是直径的假设不符,因此不存在c,证明完成. #include <queue> #i…
Computer Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 4440    Accepted Submission(s): 2236 Problem Description A school bought the first computer some time ago(so this computer's id is 1). Du…
题目链接:http://acm.split.hdu.edu.cn/showproblem.php?pid=2196 给你n个点,n-1条边,然后给你每条边的权值.输出每个点能对应其他点的最远距离是多少. 树形dp,2次dfs. 第一次 dfs1自低向上回溯更新:dp[i][0]表示从底部到i点的最远距离,dp[i][1]则表示次远距离 (dp[i][2]时用到) dp[i][0] = max(dp[i][0], dp[i的子节点][0] + edge); 第二次 dfs2自顶向下顺着更新:dp[…
Computer Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 2764    Accepted Submission(s): 1415 Problem Description A school bought the first computer some time ago(so this computer's id is 1). Du…
题意:求树中距离每个节点的最大距离. 解题关键:两次dfs,第一次从下向上dp求出每个节点子树中距离其的最大距离和不在经过最大距离上的子节点上的次大距离(后序遍历),第二次从上而下dp求出其从父节点过来的最大距离(先序遍历). 如果vi不是u最长距离经过的节点,$d[{v_i}][2] = dist[{v_i}][u] + \max (d[u][0],d[u][2])$;如果vi是u最长距离经过的节点,$d[{v_i}][2] = dist[{v_i}][u] + \max (d[u][1],d…
Computer Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 31049    Accepted Submission(s): 3929 Problem Description A school bought the first computer some time ago(so this computer's id is 1). D…
题目链接: http://codeforces.com/gym/100114 Description The computer network of “Plunder & Flee Inc.” consists of n servers and m two-way communication links. Two servers can communicate either through a direct link, or through a chain of links, by relayi…
J. Computer Network Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100114 Description The computer network of “Plunder & Flee Inc.” consists of n servers and m two-way communication links. Two servers can communicate either thr…