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 题目大意: 给定你一颗树,每个点上有权值. 现在你每次取出这颗树的一颗子树(即点集和边集均是原图的子集的连 ...
随机推荐
- apache 工作模式
apache三种工作模式: prefork(2.4前默认)/worker/event(2.4默认)内容整理来自以下网站http://m.blog.csdn.net/article/details?id ...
- apache设置映射文件夹的配置方法
在apache的配置文件中加入以下配置 Alias /uploadImage F:/upload <Directory F:/upload/UploadFiles> Option ...
- SET QUOTED_IDENTIFIER ON
语法 SET QUOTED_IDENTIFIER { ON | OFF } 注释 当 SET QUOTED_IDENTIFIER 为 ON 时,标识符可以由双引号分隔,而文字必须由单引号分隔 ...
- PythonCrawl自学日志(2)
一.Scrapy环境的安装 1.配套组件的安装 由于开发环境是在VS2015Community中编码,默认下载的python3.5,系统是windows8.1,为此需要安装的组件有如下列表: 所有的组 ...
- Linux-ubuntu
在VMware安装ubuntu时磁盘分配如下: /boot 100MB / 2G swap 512MB /home 5G /var 1G /usr 5G+. 设置root权限:sudo passwd ...
- C++ map映射的使用方法
今天考试做了道题,用上了map,这是一道提高组联赛难度的题目,先发题目: ****************************** 1. A-B problem( dec.c/cpp/pas) . ...
- PL/SQL — 函数
函数通常用于返回特定的数据.其实质是一个有名字的PL/SQL块,作为一个schema对象存储于数据库,可以被反复执行.函数通常被作为一个表达式来调用或存储过程的一个参数,具有返回值. 一.建立函数 ...
- mongodb Install the MongoDB service
在用到mongodb时,首先要运行mongod.exe以启动mongo,这样就会出现命令框( command prompt),为了避免出现这种情况.要以服务的形式来启动mongo,这样就不会出现命令框 ...
- Ubuntu中PyCharm中字体设置
在Ubuntu安装的PyCharm与Windows不同,除了Editor中的字体.配色需要设置外,文件操作栏(File--Edit--View--Navigate--Code--Refactor--- ...
- 显示 EXCEL 的页签列表
如果你的EXCEL表有很多页签,反复点击左右箭头可能会很费时间. 不妨试试在 左箭头 或者 右箭头 上点击 右键,会有页签列表弹出.