Codeforces 338 (Div 2) Longtail Hedgehog Problem Solving report

Source: Internet
Author: User

Title Link: Http://codeforces.com/problemset/problem/615/B

The title means: to draw a hedgehog, composed of tail and spines. We ask for beauty maximum value: tail * spines.

The following excerpt from Udon's words, we savor: (not necessarily correct, oh, may want to mislead other elements ...) )

1, for all points x, find the degree of x d[x],o (N+M)

2, for all points x, to find the longest chain length at the end of Point X l[x], because the tail node requirements increment, in line with the DAG nature, starting from 1 o'clock BFS can be, O (n+m)

3, enumerate all x, compare l[x] * d[x] maximum, get the answer, O (n), total complexity O (n+m)

Spines is actually tail the last point of the degree, that is tail determined, spines naturally come out (spines equivalent to the degree)

This sentence is mainly for me: we do not want to spines the best (I have been confused by this variable = =), but to tail * spines optimal

Here's what he said:

############################ listen to udon words, Sheng Read ten years book ^_^

Sharing the next twist is not only the idea of the problem, but in fact, the general Physics control variable method:
1, find the final answer res = max (tails * spines), there are two variables
2, simplifying the problem, I first assume spines certain circumstances, the answer seems to be tails maximum, has been a classic topic
But the system is to enumerate the tails optimal values in all degrees, time-out
3, I again assume that tails unchanged, in the case, according to the definition of spines is tails the last point of the number of degrees, sigh system
Tails can determine the spines, do not wash to find the best value!!
4, Gan-like I do not wash the enumeration of degrees, enumeration tails can be

#############################

1#include <iostream>2#include <cstdio>3#include <cstdlib>4#include <cstring>5#include <algorithm>6#include <vector>7 using namespacestd;8 9typedefLong LongLL;Ten  One Const intMAXN = 1e5 +5; Avector<int>EDGE[MAXN]; - LL DP[MAXN]; -  the intMain () - { - #ifndef Online_judge -Freopen ("In.txt","R", stdin); +     #endif //Online_judge -  +     intN, M; A      while(SCANF ("%d%d", &n, &m)! =EOF) { at  -         intu, v; -          for(inti =0; I < m; i++) { -scanf"%d%d", &u, &v); - Edge[u].push_back (v); - edge[v].push_back (u); in         } -LL ans =-1; to          for(inti =1; I <= N; i++) { +Dp[i] =1; - sort (Edge[i].begin (), Edge[i].end ()); the              for(intj =0; J < Edge[i].size (); J + +) { *                 if(Edge[i][j] > i)Continue; $Dp[i] = max (Dp[i], dp[edge[i][j]]+1);Panax Notoginseng             } -ans = max (ans, dp[i]* (int) edge[i].size ()); the         } +printf"%lld\n", ans); A          for(inti =1; I <= N; i++) { the edge[i].clear (); +         } -     } $  $     return 0; -}

Codeforces 338 (Div 2) Longtail Hedgehog Problem Solving report

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.