Rape Flower Kingdom--Hangzhou Electric School Race (and check set)

Source: Internet
Author: User
Tags ming

Rape kingdom

Time limit:2000/1000 MS (java/others) Memory limit:32768/32768 K (java/others)
Total submission (s): 1609 Accepted Submission (s): 411


Problem Description Program Design Competition is coming, as the school ACM Training Team Main, Xiao Ming training has been very hard. Today the weather is good, the coach is also in a great mood, an exception to the members of the team for a day off, Xiao Ming rode his little electric donkey to the outskirts of the outing.

Out of the city soon, Xiao Ming saw a large area of rape, can not help the temptation to see the beautiful scenery, turned into, who had thought, this turn but mistakenly into the rape kingdom!

The rape kingdom survives a large number of rape spirits, a creature that loves the Fibonacci sequence in particular. In this country, there are several families, each of which belongs to only one family. When the genie is born, the body will be printed with a code, indicating the ability of the Genie, if the ability value exists in the retracement, then he will add a little prestige to the family. Xiao Ming knows the relationship between all the elves by chatting with the elves.

Now, Xiaoming wants to know the prestige value of the most prestige family in the rape kingdom, can you help him? Xiao Ming will tell you the relationship between the elves, because the whole network is too large, so xiaoming is likely to repeat some of the relationships.

Input inputs contain multiple sets of data.

The first row of each group of data contains two integers n (1 <= n <= 1000), m (1 <= m <= 5000), respectively, representing the number of elves in the rape kingdom and the number of relationship groups between sprites.
The second line contains n integers, indicating the genie's ability value K (1 <= k <= 1000000000).
Then there are m lines, each line has two different integers u, v (1 <= u, v <= N), indicating that the sprite U and Elf v belong to the same family.

Output please export the Prestige value of the family with the highest prestige value, and each set of data corresponds to one row of output.

Sample Input2 11 41 2

Sample OUTPUT1

Main topic:

The Chinese question can understand not to say the meaning

Fibonacci sequence

F[0]=0;f[1]=1;

F[I]=F[I-1]+F[I-2];

On the Code

#include <stdio.h>#include<string.h>#include<algorithm>#include<iostream>using namespacestd;#defineN 10005intFei[n];intF[n];intFind (intx) {    if(x!=f[x]) f[x]=Find (f[x]); returnf[x];}intMain () {intMAXN; fei[0]=1; fei[1]=2;  for(intI=2; fei[i-1]<1000000000; i++) {Fei[i]=fei[i-1]+fei[i-2]; MAXN=i; }    intN,m,k,u,v,r[n];  while(SCANF ("%d%d", &n,&m)! =EOF) {memset (R,0,sizeof(R));  for(intI=1; i<=n;i++) {F[i]=i; scanf ("%d",&k); intIndex=lower_bound (fei,fei+maxn,k)-Fei; if(fei[index]==k) R[i]++; }         for(intI=0; i<m;i++) {scanf ("%d%d",&u,&v); intfu=Find (U); intfv=Find (v); if(fu!=FV) {F[fu]=FV; R[find (FU)]=r[fu]+R[FV]; }        }        intmax=0;  for(intI=1; i<=n;i++)        {            if(f[i]==i) Max=Max (max,r[i]); } printf ("%d\n", Max); }    return 0;}

Rape Flower Kingdom--Hangzhou Electric School Race (and check set)

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.