B. 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 ≤ 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.

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的最大值 ans=图中一条点权严格递增的链的长度乘以终点的度

题解:dp[i] 为以i为终点的满足条件的链的长度  并且计算每个点的度    枚举乘积取max输出

 #pragma comment(linker, "/STACK:102400000,102400000")
#include <cstdio>
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <cctype>
#include <map>
#include <set>
#include <queue>
#include <bitset>
#include <string>
#include <complex>
#define ll __int64
using namespace std;
int n,m;
map<int,ll>du;
struct node
{
int to;
int pre;
}N[];
int pre[];
int nedge=;
void add(int s,int t)
{
nedge++;
N[nedge].to=t;
N[nedge].pre=pre[s];
pre[s]=nedge;
}
ll dp[];
int main()
{
scanf("%d %d",&n,&m);
int x,y;
du.clear();
for(int i=;i<=n;i++){
dp[i]=;
}
for(int i=;i<=m;i++){
scanf("%d %d",&x,&y);
add(x,y);
add(y,x);
du[x]++;
du[y]++;
}
for(int i=;i<=n;i++)
{
for(int j=pre[i];j;j=N[j].pre)
{
if(N[j].to<i)
{
dp[i]=max(dp[i],dp[N[j].to]+);
}
}
}
ll ans=;
for(int i=;i<=n;i++){
ans=max(ans,du[i]*dp[i]);
}
printf("%I64d\n",ans);
return ;
}

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

  1. 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 ...

  2. Codeforces Round #338 (Div. 2) B. Longtail Hedgehog dp

    B. Longtail Hedgehog 题目连接: http://www.codeforces.com/contest/615/problem/B Description This Christma ...

  3. 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 ...

  4. 严格递增类的dp Codeforces Round #371 (Div. 1) C dp

    http://codeforces.com/contest/713 题目大意:给你一个长度为n的数组,每次有+1和-1操作,在该操作下把该数组变成严格递增所需要的最小修改值是多少 思路:遇到这类题型, ...

  5. 很好的一个dp题目 Codeforces Round #326 (Div. 2) D dp

    http://codeforces.com/contest/588/problem/D 感觉吧,这道题让我做,我应该是不会做的... 题目大意:给出n,L,K.表示数组的长度为n,数组b的长度为L,定 ...

  6. Codeforces Round #548 (Div. 2) C dp or 排列组合

    https://codeforces.com/contest/1139/problem/C 题意 一颗有n个点的树,需要挑选出k个点组成序列(可重复),按照序列的顺序遍历树,假如经过黑色的边,那么这个 ...

  7. Codeforces Round #536 (Div. 2) E dp + set

    https://codeforces.com/contest/1106/problem/E 题意 一共有k个红包,每个红包在\([s_i,t_i]\)时间可以领取,假如领取了第i个红包,那么在\(d_ ...

  8. Codeforces Round #541 (Div. 2) G dp + 思维 + 单调栈 or 链表 (连锁反应)

    https://codeforces.com/contest/1131/problem/G 题意 给你一排m个的骨牌(m<=1e7),每块之间相距1,每块高h[i],推倒代价c[i],假如\(a ...

  9. Codeforces Round #543 (Div. 2) F dp + 二分 + 字符串哈希

    https://codeforces.com/contest/1121/problem/F 题意 给你一个有n(<=5000)个字符的串,有两种压缩字符的方法: 1. 压缩单一字符,代价为a 2 ...

随机推荐

  1. Spark配置参数的三种方式

    1.Spark 属性Spark应用程序的运行是通过外部参数来控制的,参数的设置正确与否,好与坏会直接影响应用程序的性能,也就影响我们整个集群的性能.参数控制有以下方式:(1)直接设置在SparkCon ...

  2. MySQL-MMM方案

    参考文档: 官方文档:http://mysql-mmm.org/mmm2:guide 本文对mmm方案做简单介绍,并做1个简单的验证. 一.MySQL-MMM方案 1. MMM方案简介 MMM(Mul ...

  3. AppCan 之初体验

    平台概述 什么是AppCan 移步这里,楼主的一句话:可以匹敌 Phonegap .Titanium .Sencha Touch .MUI .ImagApp.Nitrous .apicloud .起步 ...

  4. Python中的构造函数

    Python中的构造函数是__init__函数.在Python中,子类如果定义了构造函数,而没有调用父类的,那么Python不会自动调用,也就是说父类的构造函数不会执行. 比如有test.py的mod ...

  5. 作业要求20181113-4 Beta阶段第1周/共2周 Scrum立会报告+燃尽图 02

    作业要求:https://edu.cnblogs.com/campus/nenu/2018fall/homework/2384 版本控制:[https://git.coding.net/lglr201 ...

  6. 随机生成30道四则运算题NEW

    代码: #include <iostream> #include <time.h> using namespace std; void main() { srand((int) ...

  7. FivePlus——成果展示

    思路描述:描述对于自己此次任务是如何思考的 这次作业没能帮上什么忙,刚开始还对这次作业有所期待,然而,第一次听他们讨论的时候就??? 之后又去查了一些诸如贪吃蛇类的小游戏,知道大概可以达成什么效果,但 ...

  8. HDU 5391Z ball in Tina Town 数论

    题目链接: hdu:http://acm.hdu.edu.cn/showproblem.php?pid=5391 bc:  http://bestcoder.hdu.edu.cn/contests/c ...

  9. Dijkstra+优先队列 模板

    #include<bits/stdc++.h> using namespace std; #define ll long long ; const ll inf=1e17; struct ...

  10. XML XPath语法总结

    刚刚遇到一个多重查询xmlDoc.SelectSingleNode("Root/Element[@Name='大气象'][@Age='30']")根据innerText查询xmlD ...