/*
CODECHEF
Problem code: FIRESC
#include<stdio.h>
inline int min(int a,int b)
{
if (a<b)
return a;
else
return b;
}
int t,n,m,x,y,i,j,id[100002],sz[100002],count,ng;
int find(int p)
{
while (p != id[p])
p = id[p];
return p;
}
int connected(int p, int q)
{
if(find(p) == find(q))
return 1;
else
return 0;
}
void uni(int p, int q)
{
int i = find(p);
int j = find(q);
if(i == j)
return;
if(sz[i] < sz[j])
{
id[i] = j;
sz[j] += sz[i];
sz[i]=1;
}
else
{
id[j] = i;
sz[i] += sz[j];
sz[j]=1;
}
count--;
}
int main()
{
unsigned long long r;
scanf("%d",&t);
while(t--)
{
int h[100002]={0},c=0;
ng=0;
r=1;
scanf("%d%d",&n,&m);
count=n;
for(i=1;i<=n;i++)
{
id[i] = i;
sz[i] = 1;
}
for(i=0;i<m;i++)
{
scanf("%d%d",&x,&y);
uni(x,y);
if(h[x]==0)
{
c++;
h[x]=1;
}
if(h[y]==0)
{
c++;
h[y]=1;
}
}
for(i=1;i<=n;i++)
if(sz[i]>1)
{
r = (r*sz[i])%1000000007;
ng++;
}
printf("%d %llu\n",ng+n-c,r);
}
return 0;
}
0 comments:
Post a Comment