B. Longtail Hedgehog

题目连接:

http://www.codeforces.com/contest/615/problem/B

Description

This Christmas Santa gave Masha a magic picture and a pencil. The picture consists of n points connected by m segments (they might cross in any way, that doesn't matter). No two segments connect the same pair of points, and no segment connects the point to itself. Masha wants to color some segments in order paint a hedgehog. In Mashas mind every hedgehog consists of a tail and some spines. She wants to paint the tail that satisfies the following conditions:

Only segments already presented on the picture can be painted;

The tail should be continuous, i.e. consists of some sequence of points, such that every two neighbouring points are connected by a colored segment;

The numbers of points from the beginning of the tail to the end should strictly increase.

Masha defines the length of the tail as the number of points in it. Also, she wants to paint some spines. To do so, Masha will paint all the segments, such that one of their ends is the endpoint of the tail. Masha defines the beauty of a hedgehog as the length of the tail multiplied by the number of spines. Masha wants to color the most beautiful hedgehog. Help her calculate what result she may hope to get.

Note that according to Masha's definition of a hedgehog, one segment may simultaneously serve as a spine and a part of the tail (she is a little girl after all). Take a look at the picture for further clarifications.

Input

First line of the input contains two integers n and m(2 ≤ n ≤ 100 000, 1 ≤ m ≤ 200 000) — the number of points and the number segments on the picture respectively.

Then follow m lines, each containing two integers ui and vi (1 ≤ ui, vi ≤ n, ui ≠ vi) — the numbers of points connected by corresponding segment. It's guaranteed that no two segments connect the same pair of points.

Output

Print the maximum possible value of the hedgehog's beauty

Sample Input

8 6

4 5

3 5

2 5

1 2

2 8

6 7

Sample Output

9

Hint

题意

给你一个图,然后你可以选择连续的一段,成为刺猬的脊梁,这个脊梁的要求是点上的编号必须依次增大

然后他的贡献是这个脊梁的长度*脊梁最后一个点的边数。

问你这个图最大的贡献是多少

题解:

直接dp处理就好了,dp[i]表示到i点的最长长度,很显然dp[i] = max(dp[i],dp[j]+1)(j<i)

然后从小到大一直跑就好了

代码

#include<bits/stdc++.h>
using namespace std;
#define maxn 100005
int dp[maxn];
vector<int> E[maxn];
int cnt[maxn];
int main()
{
int n,m;
scanf("%d%d",&n,&m);
for(int i=1;i<=m;i++)
{
int x,y;scanf("%d%d",&x,&y);
if(x<y)swap(x,y);
E[x].push_back(y);
cnt[x]++,cnt[y]++;
}
long long ans = 0;
for(int i=1;i<=n;i++)
{
for(int j=0;j<E[i].size();j++)
dp[i]=max(dp[i],dp[E[i][j]]);
dp[i]++;
ans = max(ans,1LL*dp[i]*cnt[i]);
}
cout<<ans<<endl;
}

Codeforces Round #338 (Div. 2) B. Longtail Hedgehog dp的更多相关文章

  1. Codeforces Round #338 (Div. 2) B. Longtail Hedgehog 记忆化搜索/树DP

    B. Longtail Hedgehog   This Christmas Santa gave Masha a magic picture and a pencil. The picture con ...

  2. Codeforces Round #338 (Div. 2) C. Running Track dp

    C. Running Track 题目连接: http://www.codeforces.com/contest/615/problem/C Description A boy named Ayrat ...

  3. Codeforces Round #338 (Div. 2)

    水 A- Bulbs #include <bits/stdc++.h> using namespace std; typedef long long ll; const int N = 1 ...

  4. Codeforces Round #338 (Div. 2) B dp

    B. Longtail Hedgehog time limit per test 3 seconds memory limit per test 256 megabytes input standar ...

  5. Codeforces Round #174 (Div. 1) B. Cow Program(dp + 记忆化)

    题目链接:http://codeforces.com/contest/283/problem/B 思路: dp[now][flag]表示现在在位置now,flag表示是接下来要做的步骤,然后根据题意记 ...

  6. Codeforces Round #338 (Div. 2) E. Hexagons 讨论讨论

    E. Hexagons 题目连接: http://codeforces.com/contest/615/problem/E Description Ayrat is looking for the p ...

  7. Codeforces Round #338 (Div. 2) D. Multipliers 数论

    D. Multipliers 题目连接: http://codeforces.com/contest/615/problem/D Description Ayrat has number n, rep ...

  8. Codeforces Round #338 (Div. 2) A. Bulbs 水题

    A. Bulbs 题目连接: http://www.codeforces.com/contest/615/problem/A Description Vasya wants to turn on Ch ...

  9. Codeforces Round #338 (Div. 2) D 数学

    D. Multipliers time limit per test 2 seconds memory limit per test 256 megabytes input standard inpu ...

随机推荐

  1. [Unity3D]UI界面之瞄准镜设置说明

    9空格设计 : 比如说4个角的图案固定,拉伸的时候不受影响 通过设置 左上右下来: 通过创建Image对象,将设置好的图片关联到Source Image 调整瞄准镜跟随飞机, 注意这里设置的Z轴向量是 ...

  2. [.net 面向对象程序设计进阶] (23) 团队开发利器(二)优秀的版本控制工具SVN(上)

    [.net 面向对象程序设计进阶] (23) 团队开发利器(二)优秀的版本控制工具SVN(上) 本篇导读: 上篇介绍了常用的代码管理工具VSS,看了一下评论,很多同学深恶痛绝,有的甚至因为公司使用VS ...

  3. Facebook Paper使用的第三方库

    Facebook Paper使用的第三方库 第三方库名 简介 链接 ACE code editor https://github.com/ajaxorg/ace Appirater 用户评分组件 ht ...

  4. java selenium针对多种情况的多窗口切换

    一.通过按钮点击打开的新页面,不涉及到打开多窗口,只要在已有打开的窗口实现切换操作即可 Set<String> winHandels = driver.getWindowHandles() ...

  5. Openwrt iptables分析

    这里将载有Openwrt的WR841N的路由表dump出来分析一下. 这个是dump出iptables的命令 root@OpenWrt:/etc/config# iptables-save 这里分为4 ...

  6. Oracle11g 32位安装步骤

    1.注意Oracle分成两个文件,下载完后,将两个文件解压到同一目录下即可. 路径名称中,最好不要出现中文,也不要出现空格等不规则字符.官方下地址:http://www.oracle.com/tech ...

  7. [topcoder]FlowerGarden

    1.此题很勉强算DP.找了半天网上思路,是个三层的循环,n^3.2.基本思路就是先找到在第一个位置的花.这样就双层遍历,找到所有和其他不冲突的花中最高的一个,然后放到结果的首位.然后去掉此花,继续使用 ...

  8. Eclipse关联Java源代码

    一个很简单的技巧,不多说,直接贴图 1. 2 . 3.选择你jdk下的src.zip就可以了.搞定!

  9. 用JavaScript实现图片剪切效果

    学会如何获取鼠标的坐标位置以及监听鼠标的按下.拖动.松开等动作事件,从而实现拖动鼠标来改变图片大小. 还可以学习css中的clip属性. 一.CSS实现图片不透明及裁剪效果. 图片剪切三层结构 1.第 ...

  10. Python之编写登录接口

    作业:编写登陆接口 输入用户名密码 认证成功后显示欢迎信息 输错三次后锁定 帐号文件account.txt内容如下: liuyueming 123zhangsan 123lisi 123 锁文件acc ...