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 ofn 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 theendpoint 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 andm(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 integersui andvi
(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 numbers1,
2 and 5. The following segments are spines: (2,
5), (3,
5) and (4,5). Therefore, the beauty of the hedgehog is equal to3·3 = 9.

n个点,m条无向边,在连成的链中找一条递增的链,使得末尾节点的度数乘以深度最大,因为是无向边,又要求递增的链,所以尽量使小的数做起点,并且将所有的边按照节点大小进行排序,从最小的点开始遍历,记录每一个点最大的深度,然后找到最大的乘积

#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
struct node
{
int u,v;
}edge[200000+10];
bool cmp(node s1,node s2)
{
if(s1.u==s2.u)
return s1.v<s2.v;
return s1.u<s2.u;
}
int main()
{
int n,m;
cin>>n>>m;
__int64 dp[100100],dre[100100];
memset(dp,0,sizeof(dp));
memset(dre,0,sizeof(dre));
for(int i=0;i<m;i++)
{
cin>>edge[i].u>>edge[i].v;
if(edge[i].u>edge[i].v)
swap(edge[i].u,edge[i].v);//¾¡Á¿Ê¹Ð¡µÄµã×öÆðµã
dre[edge[i].u]++,dre[edge[i].v]++;
}
sort(edge,edge+m,cmp);
for(int i=0;i<m;i++)//¼Ç¼ÿһ¸öµãµÄ×î´óÉî¶È
dp[edge[i].v]=max(dp[edge[i].v],dp[edge[i].u]+1);
__int64 ans=0;
for(int i=1;i<=n;i++)
ans=max(ans,(dp[i]+1)*dre[i]);//Ñ°ÕÒ×î´ó³Ë»ý
cout<<ans<<endl;
return 0;
}

Codeforces--615B--Longtail Hedgehog(贪心模拟)的更多相关文章

  1. CodeForces 615B Longtail Hedgehog

    题目: http://codeforces.com/problemset/problem/615/B 题意:题目描述很复杂,但实际上很简单.大意就是连续的几个点组成尾巴,要求尾巴的长度乘以尾巴终点的分 ...

  2. CodeForces ---596B--Wilbur and Array(贪心模拟)

    Wilbur and Array Time Limit: 2000MS   Memory Limit: 262144KB   64bit IO Format: %I64d & %I64u Su ...

  3. Codeforces 158 B. Taxi[贪心/模拟/一辆车最多可以坐4人同一个群的小朋友必须坐同一辆车问最少需要多少辆车]

    http://codeforces.com/problemset/problem/158/B B. Taxi time limit per test 3 seconds memory limit pe ...

  4. 贪心+模拟 Codeforces Round #288 (Div. 2) C. Anya and Ghosts

    题目传送门 /* 贪心 + 模拟:首先,如果蜡烛的燃烧时间小于最少需要点燃的蜡烛数一定是-1(蜡烛是1秒点一支), num[g[i]]记录每个鬼访问时已点燃的蜡烛数,若不够,tmp为还需要的蜡烛数, ...

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

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

  6. codeforces 615 B. Longtail Hedgehog (DFS + 剪枝)

    题目链接: codeforces 615 B. Longtail Hedgehog (DFS + 剪枝) 题目描述: 给定n个点m条无向边的图,设一条节点递增的链末尾节点为u,链上点的个数为P,则该链 ...

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

  8. codeforces 704B - Ant Man 贪心

    codeforces 704B - Ant Man 贪心 题意:n个点,每个点有5个值,每次从一个点跳到另一个点,向左跳:abs(b.x-a.x)+a.ll+b.rr 向右跳:abs(b.x-a.x) ...

  9. Longtail Hedgehog(DP)

    Longtail Hedgehog time limit per test 3 seconds memory limit per test 256 megabytes input standard i ...

随机推荐

  1. Codeforces_731F_(前缀和)

    F. Video Cards time limit per test 1 second memory limit per test 256 megabytes input standard input ...

  2. windows下使用批处理设置环境变量

    1. 设置临时环境变量 set BAT_HOME=c:\bat 此命令只对当前窗口有效,批处理或cmd窗口一关闭,变量就恢复原来的值了. 2. 设置永久环境变量 方法一 setx BAT_HOME C ...

  3. centOS7创建python虚拟环境

    参考: 非常棒的2篇博客 https://www.centos.bz/2018/05/centos-7-4-%E5%AE%89%E8%A3%85python3%E5%8F%8A%E8%99%9A%E6 ...

  4. Java中面向对象三大特性之——多态

    多态的概述:  多态是继封装.继承之后,面向对象的第三大特性. 生活中,比如跑的动作,小猫.小狗和大象,跑起来是不一样的.再比如飞的动作,昆虫.鸟类和飞机,飞起来也是不一样的.可见,同一行为,通过不同 ...

  5. 10.3 io流 正篇 FileReader FileWriter读写代码

    一.FileWriter 小节: 1)FileWriter fw = new FileWriter("a.txt",true);//表示追加写入,默认是false.正常情况:执行多 ...

  6. vC web管理无法访问解决办法

    localhost:~ # service-control --status vsphere-clientINFO:root:Service: vsphere-client, Action: stat ...

  7. Python学习【第6篇】:Python之常用模块1

    常用模块一. collocations 模块 时间模块 random模块 os模块 sys模块 序列化模块 re模块 常用模块二:这些模块和面向对象有关 hashlib模块 configparse模块 ...

  8. POJ——3169Layout(差分约束)

    POJ——3169Layout Layout Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 14702   Accepted ...

  9. 34.分组聚合操作—bucket

    主要知识点: 学习聚合知识     一.准备数据     1.家电卖场案例背景建立index 以一个家电卖场中的电视销售数据为背景,来对各种品牌,各种颜色的电视的销量和销售额,进行各种各样角度的分析 ...

  10. 基本数据类型:字符串(str)

    一.字符串的定义和创建 字符串是一个有序的字符的集合,用于存储和表示基本的文本信息,' '或'' ''或''' '''中间包含的内容称之为字符串,总之加了引号的字符都被认为是字符串! 创建: > ...