Codeforces 14D
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
const int MAX = 205;
int dep, n, map[MAX][MAX];
int dfs(int u, int v){
int max1, max2, path_max;
max1 = max2 = path_max = 0;
for(int i = 1;i <= n;i ++){
if(map[i][u] && i != v){
int z = dfs(i, u);
if(path_max < z) path_max = z;
if(max1 < dep){
max2 = max1;
max1 = dep;
}
else if(max2 < dep) max2 = dep;
}
}
if(path_max < max1 + max2) path_max = max2 + max1;
dep = max1 + 1;
return path_max;
} int main(int argc, char const *argv[]){
int u, v;
//freopen("in.c", "r", stdin);
while(~scanf("%d", &n)){
memset(map, 0, sizeof(map));
for(int i = 0; i < n - 1;i ++){
scanf("%d%d", &u, &v);
map[u][v] = map[v][u] = 1;
}
int ans = -1;
for(int i = 1;i <= n;i ++){
for(int j = 1;j <= n;j ++){
if(map[i][j]){
int a = dfs(i, j);
int b = dfs(j, i);
ans = max(ans, a*b);
}
}
}
printf("%d\n", ans);
}
return 0;
}
Codeforces 14D的更多相关文章
- Codeforces 14D Two Paths 树的直径
题目链接:点击打开链接 题意:给定一棵树 找2条点不反复的路径,使得两路径的长度乘积最大 思路: 1.为了保证点不反复,在图中删去一条边,枚举这条删边 2.这样得到了2个树,在各自的树中找最长链.即树 ...
- CodeForces 14D 树的直径 Two Paths
给出一棵树,找出两条不相交即没有公共点的路径,使得两个路径的长度的乘积最大. 思路:枚举树中的边,将该边去掉,分成两棵树,分别求出这两棵树的直径,乘起来维护一个最大值即可. #include < ...
- codeforces 14D(搜索+求树的直径模板)
D. Two Paths time limit per test 2 seconds memory limit per test 64 megabytes input standard input o ...
- python爬虫学习(5) —— 扒一下codeforces题面
上一次我们拿学校的URP做了个小小的demo.... 其实我们还可以把每个学生的证件照爬下来做成一个证件照校花校草评比 另外也可以写一个物理实验自动选课... 但是出于多种原因,,还是绕开这些敏感话题 ...
- 【Codeforces 738D】Sea Battle(贪心)
http://codeforces.com/contest/738/problem/D Galya is playing one-dimensional Sea Battle on a 1 × n g ...
- 【Codeforces 738C】Road to Cinema
http://codeforces.com/contest/738/problem/C Vasya is currently at a car rental service, and he wants ...
- 【Codeforces 738A】Interview with Oleg
http://codeforces.com/contest/738/problem/A Polycarp has interviewed Oleg and has written the interv ...
- CodeForces - 662A Gambling Nim
http://codeforces.com/problemset/problem/662/A 题目大意: 给定n(n <= 500000)张卡片,每张卡片的两个面都写有数字,每个面都有0.5的概 ...
- CodeForces - 274B Zero Tree
http://codeforces.com/problemset/problem/274/B 题目大意: 给定你一颗树,每个点上有权值. 现在你每次取出这颗树的一颗子树(即点集和边集均是原图的子集的连 ...
随机推荐
- lsof作用
lsof 卸载移动存储时经常提示device busy,也可能误删了一个正在打开的文件.... 这时候可以试试lsof lsof简介 lsof(list open files)是一个列出当前系统打 ...
- 《C和指针》读书笔记——第一章 快速上手
1.注释代码可以用: #if 0 statements #endif 2.参数被声明为const,表明函数将不会修改函数调用者的所传递的这个参数. 3.scanf("%d",&am ...
- awk的使用备忘
[转]http://www.cnblogs.com/mydomain/archive/2012/09/24/2699467.html awk引用外部变量 一.用awk 有以下几种方法去调用变量: ...
- C#微信登录-电脑版扫描二维码登录
像京东,一号店等网站都实现了用微信来登录的功能,就是用手机上的微信扫一扫网站上的二维码,微信上确认后,即可自动用微信的帐号登录网站. 一.创建网站应用 在微信开放平台创建一个网站应用 https:// ...
- iOS 8 定位失败问题
首先plist定义两个string: NSLocationWhenInUseUsageDescription NSLocationAlwaysUsageDescription 然后调用 [self. ...
- Automotive Security的一些资料和心得(2):Cryptography
1. Security Goal - Confidentiality - Integrity - Availability - Authenticity - Non-repudiation - Aut ...
- DIY RazorEngine 的程序集生成方式
最近遇到一个项目,要使用RazorEngine做模板引擎,然后完成简易的CMS功能,以减轻重复的CDRU操作,同时复用管理后台.没错,使用的正是GIT HUB上的开源项目:https://github ...
- spoj LCS
初识后缀自动机: 推荐学习:http://blog.sina.com.cn/s/blog_7812e98601012dfv.html #include<cstdio> #include&l ...
- SPRING IN ACTION 第4版笔记-第七章Advanced Spring MVC-006- 如何保持重定向的request数据(用model、占位符、RedirectAttributes、model.addFlashAttribute("spitter", spitter);)
一.redirect为什么会丢数据? when a handler method completes, any model data specified in the method is copied ...
- VC 透明滑动控件Slider Control
操作系统:Windows 7软件环境:Visual C++ 2008 SP1本次目的:为滑动控件设置背景透明 经常在编写有背景的程序时,滑动控件Slider Control看起来与背景十分不合,我们可 ...