Longtail Hedgehog
time limit per test

3 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

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:

  1. Only segments already presented on the picture can be painted;
  2. 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;
  3. 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 ≤ nui ≠ 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.

Examples
input
8 6 4 5 3 5 2 5 1 2 2 8 6 7
output
9
input
4 6 1 2 1 3 1 4 2 3 2 4 3 4
output
12
Note

The picture below corresponds to the first sample. Segments that form the hedgehog are painted red. The tail consists of a sequence of points with numbers 1, 2 and 5. The following segments are spines: (2, 5), (3, 5) and (4, 5). Therefore, the beauty of the hedgehog is equal to 3·3 = 9.

题解:让画出一个最美的刺猬,刺猬由尾巴和刺构成,尾巴是一个递增的数列,魅力值是尾巴的长度乘以刺的个数,刺是选尾巴上的一个点,这个点所连的边都是刺;

很容易得出ans=max(dp[i]*G[i]);dp代表的是尾巴的长度;

代码:

#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<map>
#include<string>
#include<vector>
using namespace std;
const int INF=0x3f3f3f3f;
#define SI(x) scanf("%d",&x)
#define PI(x) printf("%d",x)
#define P_ printf(" ")
#define mem(x,y) memset(x,y,sizeof(x))
const int MAXN=;
vector<int>vec[MAXN];
int dp[MAXN];
typedef __int64 LL;
LL MAX(LL a,LL b){
return a>b?a:b;
}
int main(){
int m,n;
while(~scanf("%d%d",&n,&m)){
for(int i=;i<MAXN;i++)vec[i].clear();
while(m--){
int a,b;
scanf("%d%d",&a,&b);
vec[a].push_back(b);
vec[b].push_back(a);
}
mem(dp,);
for(int i=;i<=n;i++){
for(int j=;j<vec[i].size();j++){
if(vec[i][j]<i)dp[i]=MAX(dp[i],dp[vec[i][j]]+);
}
}
LL ans=;
for(int i=;i<=n;i++)ans=MAX(ans,(LL)(dp[i]+)*vec[i].size());
printf("%I64d\n",ans);
}
return ;
}

Longtail Hedgehog(DP)的更多相关文章

  1. LightOJ 1033 Generating Palindromes(dp)

    LightOJ 1033  Generating Palindromes(dp) 题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid= ...

  2. lightOJ 1047 Neighbor House (DP)

    lightOJ 1047   Neighbor House (DP) 题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=87730# ...

  3. UVA11125 - Arrange Some Marbles(dp)

    UVA11125 - Arrange Some Marbles(dp) option=com_onlinejudge&Itemid=8&category=24&page=sho ...

  4. 【POJ 3071】 Football(DP)

    [POJ 3071] Football(DP) Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 4350   Accepted ...

  5. 初探动态规划(DP)

    学习qzz的命名,来写一篇关于动态规划(dp)的入门博客. 动态规划应该算是一个入门oier的坑,动态规划的抽象即神奇之处,让很多萌新 萌比. 写这篇博客的目标,就是想要用一些容易理解的方式,讲解入门 ...

  6. Tour(dp)

    Tour(dp) 给定平面上n(n<=1000)个点的坐标(按照x递增的顺序),各点x坐标不同,且均为正整数.请设计一条路线,从最左边的点出发,走到最右边的点后再返回,要求除了最左点和最右点之外 ...

  7. 2017百度之星资格赛 1003:度度熊与邪恶大魔王(DP)

    .navbar-nav > li.active > a { background-image: none; background-color: #058; } .navbar-invers ...

  8. Leetcode之动态规划(DP)专题-详解983. 最低票价(Minimum Cost For Tickets)

    Leetcode之动态规划(DP)专题-983. 最低票价(Minimum Cost For Tickets) 在一个火车旅行很受欢迎的国度,你提前一年计划了一些火车旅行.在接下来的一年里,你要旅行的 ...

  9. 最长公共子序列长度(dp)

    /// 求两个字符串的最大公共子序列长度,最长公共子序列则并不要求连续,但要求前后顺序(dp) #include <bits/stdc++.h> using namespace std; ...

随机推荐

  1. Implement Trie (Prefix Tree) 解答

    Question Implement a trie with insert, search, and startsWith methods. Note:You may assume that all ...

  2. 那些年的那些事CISC和RISC发展中的纠缠

    本文来自http://www.cnbeta.com/articles/224544.htm ARM.ARM.ARM,没错ARM仿佛一夜之间就火了,平板.手机等领域随处可见它的影子,甚至已经有人预言未来 ...

  3. 【转】【漫画解读】HDFS存储原理

    根据Maneesh Varshney的漫画改编,以简洁易懂的漫画形式讲解HDFS存储机制与运行原理. 一.角色出演 如上图所示,HDFS存储相关角色与功能如下: Client:客户端,系统使用者,调用 ...

  4. C++ Primer 学习笔记_69_面向对象编程 --继承情况下的类作用域

    面向对象编程 --继承情况下的类作用域 引言: 在继承情况下,派生类的作用域嵌套在基类作用域中:假设不能在派生类作用域中确定名字,就在外围基类作用域中查找该名字的定义. 正是这样的类作用域的层次嵌套使 ...

  5. 说说ShellExecuteEx

    今天来说说ShellExecuteEx这个函数,先翻译MSDN,然后看个样例. ShellExecuteEx Function 对指定应用程序运行某个操作 语法: BOOL ShellExecuteE ...

  6. Head First C#(赛狗日)

    实验背景: 人:Joe.Bob和AI希望参见赛狗赌博.最初,Joe有50元,Bob有75元,AI有45元.每次比赛前,他们都会各自决定是否下注以及所押的赌金.直到比赛前,他们都可以改变赌金,但是一旦比 ...

  7. Linux shell 的 test 命令用法详解

    基本格式:test expression expression为test命令构造的表达式.这里expression是test命令可以理解的任何有效表达式,该简化格式将是读者可能会踫见的最常用格式返回值 ...

  8. ExtJs4.0入门错误

    当在eclipse中的web工程中增加了extjs4,出现An internal error occurred during: "Building workspace". Java ...

  9. C#获取本机IP方法,获取本机局域网IP地址方法

    1. private void GetIP() { string hostName = Dns.GetHostName();//本机名 //System.Net.IPAddress[] address ...

  10. What is SignalR and Why Should I Use It?

    原文地址: What is SignalR and why should I use it? When I first heard about SignalR, I was not sure what ...