Codeforces Round #338 (Div. 2) B. Longtail Hedgehog Memory Search/Tree DP

Source: Internet
Author: User

B. Longtail Hedgehog

This Christmas Santa gave Masha a magic picture and a pencil. The picture consists of n points connected by m segments (they might cross on any-, that does N ' t matter). No. 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 is continuous, i.e consists of some sequence of points, such that every and neighbouring points are Conne CTED 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 doing so, Masha would paint all the segments, such that one of the 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 is 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's a little girl after all). Take a look at the picture for further clarifications.

Input

First line of the input contains, integers n and m(2≤ n ≤100, 1≤ M ≤200)-the number of points and the number segments on the picture respectively.

Then follow m lines, each containing, integers ui and vi< /c9> (1≤ ui, vin, u ivi)-the numbers of points connected by corresponding segment. It's guaranteed that no segments connect the same pair of points.

Output

Print the maximum possible value of the Hedgehog ' s beauty.

Sample Test (s) 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 is painted red. The tail consists of a sequence of points with numbers 1, 2 and 5. The following segments is spines: (2, 5), (3, 5) and (4, 5). Therefore, the beauty of the Hedgehog is equal to 3 3 = 9.

Test Instructions : give you n points m edge, let you find a longest chain, output the largest chain length * and linked to the end of the link node points

Puzzle: We can remember the longest chain, and record the longest length of each point.

Attention will explode int

#include <bits/stdc++.h>#include<iostream>#include<cstdio>#include<cmath>#include<cstring>#include<algorithm>using namespacestd; typedefLong Longll;Const intN =1010000; Vector<ll >G[n];ll n,m,no,a,b,sum,last,dp[n];ll Dfs (ll x,ll s) {if(Dp[x])returnDp[x]; ll mm=0;  for(intI=0; I<g[x].size (); i++) {        if(G[x][i] <x) {mm= Max (Dfs (g[x][i],s+1), MM); }    }    returnDP[X] = mm +1;}intMain () {scanf ("%i64d%i64d",&n,&m);  for(intI=1; i<=m;i++) {scanf ("%i64d%i64d",&a,&b);        G[a].push_back (b);    G[b].push_back (a); } ll mm=0; ll A=0; ll nn=0;  for(inti=n;i>=1; i--) {sum=g[i].size (); MM= DFS (i,1); A= Max (a,sum*mm); } printf ("%i64d\n", A); return 0;}
Daima

Codeforces Round #338 (Div. 2) B. Longtail Hedgehog Memory Search/Tree DP

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.