The test of rqnoj343 mty

Source: Internet
Author: User

Title Description

Ah! After several setbacks. Mty finally found his idol. He is ... fyc!

But fyc such a senior person does not like a person always haunt him. So he had a problem to test mty.fyc have a few men: Chen Letian, shu step chicken, Wei Hu ... Now FYC is going to fight with others and need to set up a value army. Soldiers of the army were chosen by FYC's men.

In order to form an army, the compulsory meeting of each person in the army has a direct or indirect relationship of friendship.

So mty now needs to form a troop of the largest number of people to meet the above situation.

Problem Size:

For 100% of data, 1<=n<=1000,1<=m<=500.

Input format first line, two number, n,m. (n means that FYC has several men m indicating that there is M-to-friend relationship).

M-line, two numbers per line. x[i],y[i]. The person who is numbered X[i],y[i] is a friend.

The output format is a number that represents the largest number of troops in the army.

Sample input

5 3
1 2
2 3
3 4

Sample output

4
Description: 1,2,3,4 can form the army all the time.

`#include <iostream>#include<cstdio>#include<string>#include<cstring>#include<algorithm>using namespacestd;Const intMAXN =1050;intn,m;intF[MAXN],SZ[MAXN];intFINDF (intx) {    returnx = = F[x]? X:F[X] =findf (f[x]);}intMain () {CIN>>n>>m;  for(inti =1; I <= n;i++) {F[i]=i; Sz[i]=1; }    intX,y,fx,fy;  for(inti =1; I <= m;i++) {scanf ("%d%d",&x,&y); FX=findf (x); FY=findf (y); if(FX = = FY)Continue;//Notice        if(Sz[fx] >Sz[fy]) swap (FX,FY); SZ[FY]+=SZ[FX]; F[FX]=fy; }    intAns =0;  for(inti =1; I <= n;i++){        if(Ans < sz[i]) ans =Sz[i]; } cout<<ans; return 0;} #include<iostream>using namespacestd;intfather[1001];intFindintx) {    if(X!=father[x]) father[x]=find (father[x]); returnfather[x];}voidUnintFintz) {Father[z]=F;}intMain () {inta[1001]={0}; intans=0; intn,m; intx, y; CIN>>n>>m;  for(intI=1; i<=n;i++) {Father[i]=i; }     for(intI=1; i<=m;i++) {cin>>x>>y;    Un (find (x), find (y)); }     for(intI=1; i<=n;i++) {a[find (i)]++; Ans=Max (A[find (i)],ans); } cout<<ans; //System ("pause");    return 0;}`

The test of rqnoj343 mty

Related Keywords:

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.