HDU 5325 Crazy Bobo

Source: Internet
Author: User

HDU 5325 Crazy Bobo

Set the direction of the original edge (u, v) to u-> v when w [u]> w [v]

The maximum Set is the Set of vertices reached by max {u}

 

Crazy Bobo Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 131072/65536 K (Java/Others)
Total Submission (s): 382 Accepted Submission (s): 116



Problem Description Bobo has a tree, whose vertices are conveniently labeled by 1, 2,..., n. Each node has a weight Wi . All the weights are distrinct.
A set with m nodes V1, v2,..., vm Is a Bobo Set if:
-The subgraph of his tree induced by this set is connected.
-After we sort these nodes in set by their weights in ascending order, we get U1, u2,..., um , (That is, Wui For I from 1 M-1). For any node X In the path from Ui To Ui + 1 (Excluding Ui And Ui + 1 ), Shoshould satisfy Wx .
Your task is to find the maximum size of Bobo Set in a given tree.

Input The input consists of several tests. For each tests:
The first line contains a integer n ( 1 ≤ n ≤500000 ). Then following a line contains n integers W1, w2,..., wn ( 1 ≤ wi ≤109 , All Wi Is distrinct). Each of the following n-1 lines contain 2 integers Ai And Bi , Denoting an edge between vertices Ai And Bi ( 1 ≤ ai, bi ≤ n ).
The sum of n is not bigger than 800000.

Output For each test output one line contains a integer, denoting the maximum size of Bobo Set.
Sample Input
73 30 350 100 200 300 4001 22 33 44 55 66 7

Sample Output
5

Source 2015 Multi-University Training Contest 3
#pragma comment(linker, /STACK:1024000000,1024000000)#include 
 
  #include 
  
   #include 
   
    #include using namespace std;typedef long long ll;#define prt(k) cout<<#k = <
    
      w[v]) g[u] = up(v) + 1;        return g[u];}int n;pair
     
       p[N];int main(){        while (scanf(%d, &n)==1) {                for (int i=1;i<=n;i++) scanf(%d, w+i), p[i]=make_pair(w[i], i);                sort(p+1, p+n+1);                mm = 0; memset(head, -1, sizeof head);                for (int i=0;i
      
       =1;i--) { int u = p[i].second; dp[u] = 1; for (int j=head[u];~j;j=e[j].next) { int v = e[j].v; if (w[u] < w[v]) dp[u] += dp[v]; } ans = max(ans, dp[u]); } printf(%d, ans); } return 0;}
      
     
    
   
  
 


 

 

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.