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. php codeigniter (CI) oracle 数据库配置-宋正河整理

    database.php 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 $active_group = 'default'; $active_record ...

  2. linux 学习网站

    study-Area:http://www.study-area.org 鸟哥的私房菜:http://linux.vbird.org 鸟哥的私房菜课后答案:http://wapwenku.baidu. ...

  3. leetcode:Integer to Roman(整数转化为罗马数字)

    Question: Given an integer, convert it to a roman numeral. Input is guaranteed to be within the rang ...

  4. python install 2.7.10

    CentOS 6.5升级Python和安装IPython 后来换成了CentOS 6.5,系统自带的Python版本是2.6.6. 图一:安装IPython需求 已经安装好gcc等编译工具.系统自带P ...

  5. ajax 模仿百度下拉

    <!doctype html> <html> <head> <meta charset="utf-8"> <title> ...

  6. java 的开源wiki维基系统

    几乎所有 维基 系统的对比网址:   http://www.wikimatrix.org/ XWiki,    第二代wiki. 它里面使用的 velocity 模板语言对j2ee开发相当有参考价值, ...

  7. ssh-keygen -t rsa -f cloud.key ssh -i cloud.key <username>@<instance_ip>

  8. Swift 可选值(Optional Values)介绍

    Optional的定义 Optional也是Objective-C没有的数据类型,是苹果引入到Swift语言中的全新类型,它的特点就和它的名字一样:可以有值,也可以没有值,当它没有值时,就是nil.此 ...

  9. js 生成随机数

    <script>   function GetRandomNum(Min,Max){   var Range = Max - Min;   var Rand = Math.random() ...

  10. codeforces 659A Round House

    A. Round House time limit per test 1 second memory limit per test 256 megabytes input standard input ...