(File IO): input: score.in output: score.out
time limit: 1000 ms space constraints: 262144 KB specific restrictions
Title Description
After completion friend statistical situation, Xiao Ming and everyone interested in graduate school, but he felt alone people counting is a very silly thing, so he designed an algorithm, the same school graduates, the first
Ge will get
minute, first
Ge obtained
points, the first
Ge obtained
points ... first
a will
points out that this elementary school scores, Xiao Ming would like to know how many schools have the highest scores points.
Enter the
input file
first row there are two integers
and
,
represents the total number of people,
represents the number of known relationship with the school.
Next
rows, each row having
by spaces separated integers
and
, represents
and b are from the same school,
and
are
to
an integer between. We will not give duplicate information.
Output
Output file score.out only one line for all schools in the highest score. The final score may be very large, 100 after you only need to output, less than 100, please direct output.
Sample input
. 5. 3
. 1 2
. 3. 4
. 1. 3
Sample output
15
Data range limit
% of the data,
% of the data,
% of the data,
prompt
resulting from the same school school score for
Problem-solving ideas
had started AC mentality to play this problem, the results of 0!
I have been saying runtime error, change a full two hours, and finally found the title is changed in the function missed one
. . . Low-level errors
in fact this question is to hit a disjoint-set, then calculate the results can be. Because the data is large, to use high precision.
Code
#include<iostream>
#include<cstring>
#include<string>
#include<cstdio>
#include<algorithm>
#include<iomanip>
#include<cmath>
using namespace std;
int n,m,a[20010],x,y,xx,yy,fat[20010],ans[20010],l,maxn,k,x1;
int getfather(int z){
if(fat[z]==0)
return z;
return fat[z]=getfather(fat[z]);
}
int main()
{
freopen("score.in","r",stdin);
freopen("score.out","w",stdout);
scanf("%d%d",&n,&m);
for(int i=1; i<=n; i++)
a[i]=1;
for(int i=1; i<=m; i++)
{
scanf("%d%d",&x,&y);
xx=getfather(x);
yy=getfather(y);
if(xx!=yy)
{
fat[xx]=yy;
a[yy]=a[xx]+a[yy];
if(a[yy]>maxn)
maxn=a[yy];
}
}
l=1;
ans[1]=1;
for(int i=1; i<=maxn; i++)
{
x1=0;
for(int j=1; j<=l; j++)
{
ans[j]=ans[j]*2+x1;
x1=ans[j]/10;
ans[j]=ans[j]%10;
}
if(x1>0)
{
l++;
ans[l]=x1;
}
if(l>100)
l=100;
}
ans[1]=ans[1]-1;
k=1;
while(ans[k]<0)
{
ans[k]+=10;
ans[k+1]--;
k++;
}
for(int i=l;i>=1;i--)
{
if(ans[l]!=0)
printf("%d",ans[i]);
}
}