cf14D Two Paths(树的直径)】的更多相关文章

题目链接: http://codeforces.com/contest/14/problem/D D. Two Paths time limit per test2 secondsmemory limit per test64 megabytes 问题描述 As you know, Bob's brother lives in Flatland. In Flatland there are n cities, connected by n - 1 two-way roads. The citie…
题目链接:点击打开链接 题意:给定一棵树 找2条点不反复的路径,使得两路径的长度乘积最大 思路: 1.为了保证点不反复,在图中删去一条边,枚举这条删边 2.这样得到了2个树,在各自的树中找最长链.即树的直径,然后相乘就可以 #include<stdio.h> #include<iostream> #include<string.h> #include<set> #include<vector> #include<map> #inclu…
 Two Paths Time Limit: 2000MS   Memory Limit: 65536KB   64bit IO Format: %I64d & %I64u Submit Status Description As you know, Bob's brother lives in Flatland. In Flatland there are n cities, connected by n - 1 two-way roads. The cities are numbered…
给出一棵树,找出两条不相交即没有公共点的路径,使得两个路径的长度的乘积最大. 思路:枚举树中的边,将该边去掉,分成两棵树,分别求出这两棵树的直径,乘起来维护一个最大值即可. #include <iostream> #include <cstdio> #include <cstring> #include <algorithm> using namespace std; + ; int n; struct Edge { int u, v, nxt; bool…
tiyi:给你n个节点和n-1条边(无环),求在这个图中找到 两条路径,两路径不相交,求能找的两条路径的长度的乘积最大值: #include <iostream> #include <cstdio> #include <cstring> #include <cstdlib> #include <cmath> #include <vector> #include <queue> #include <stack>…
H. Capital City[ Color: Black ]Bahosain has become the president of Byteland, he is doing his best to make people's liveseasier. Now, he is working on improving road networks between the cities.If two cities are strongly connected, people can use BFS…
传送门 Park Visit Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 3721    Accepted Submission(s): 1667 Problem Description Claire and her little friend, ykwd, are travelling in Shevchenko's Park! T…
D. Two Paths time limit per test 2 seconds memory limit per test 64 megabytes input standard input output standard output As you know, Bob's brother lives in Flatland. In Flatland there are n cities, connected by n - 1 two-way roads. The cities are n…
题目链接:http://poj.org/problem?id=2631 题意:给出一棵树的两边结点以及权重,就这条路上的最长路. 思路:求实求树的直径. 这里给出树的直径的证明: 主要是利用了反证法: 假设 s-t这条路径为树的直径,或者称为树上的最长路 现有结论,从任意一点u出发搜到的最远的点一定是s.t中的一点,然后在从这个最远点开始搜,就可以搜到另一个最长路的端点,即用两遍广搜就可以找出树的最长路 证明:   1.设u为s-t路径上的一点,结论显然成立,否则设搜到的最远点为T则   dis…
Cow Marathon Time Limit: 2000MS   Memory Limit: 30000K Total Submissions: 3195   Accepted: 1596 Case Time Limit: 1000MS Description After hearing about the epidemic of obesity in the USA, Farmer John wants his cows to get more exercise, so he has com…