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. 【转】从外行的视角尝试讲解为什么这回丰田栽了【全文完】【v1.01】

    转自:http://club.tgfcer.com/thread-6817371-1-1.html  [第一部分]背景简介 前几年闹得沸沸扬扬的丰田刹不住事件最近又有新进展.十月底俄克拉荷马的一次庭审 ...

  2. HDU5807 Keep In Touch (BestCoder Round #86 D ) 分布式dp

    #include <cstdio> #include <cstring> #include <cmath> #include <vector> #inc ...

  3. CMake 入门

    编写 CMakeLists.txt 首先编写 CMakeLists.txt 文件,并保存在与 main.cc 源文件同个目录下: # 单个源文件 # CMake 最低版本号要求 cmake_minim ...

  4. MXML的一些基本语法

    以下内容是一个视频的学习笔记<Flex4视频教程>,所以,先关记录也是以现在的Flash Builder为基础. <fx:Script/>  是脚本文件的声明 var代表数值, ...

  5. CAD操作

    1.建立构造线 说签名和图签不在同一条直线上,如何判断两个对向到底是不是在一条线上呢?通过构造线( Construction Line)可以进行判断,CAD中打入: xl 命令,再键入h(horizo ...

  6. uoj #58. 【WC2013】糖果公园(树上莫队算法+修改操作)

    [题目链接] http://uoj.ac/problem/58 [题意] 有一棵树,结点有自己的颜色,若干询问:u,v路径上的获益,并提供修改颜色的操作. 其中获益定义为Vc*W1+Vc*W2+…+V ...

  7. Strom学习笔记一

    ---恢复内容开始--- Storm 是个实时的.分布式以及具备高容错的计算系统.同Hadoop一样Storm也可以处理大批量的数据,然而Storm在保证高可靠性的前提下还可以让处理进行的更加实时:也 ...

  8. dom 动态生产表格

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

  9. sysctl.conf

    linux系统接口 允许改变正在运作linux系统接口Tcp/IP堆栈和虚拟内存系统的高级选项 用来控制Linux网络配置/proc/sys/net/core/ TCP/IP参数修改添加到/etc/s ...

  10. Apache Spark 架构

    1.Driver:运行 Application 的 main() 函数并且创建 SparkContext. 2.Client:用户提交作业的客户端. 3.Worker:集群中任何可以运行 Applic ...