-
Notifications
You must be signed in to change notification settings - Fork 1
/
firesc.c
49 lines (47 loc) · 1.04 KB
/
firesc.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#include<stdio.h>
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
int n[100010]={0},y,x,a,b,i=1,j,teamcount[100010]={0};
scanf("%d%d",&x,&y);
while(y--)
{
scanf("%d%d",&a,&b);
if(n[a]==0&&n[b]!=0)
n[a]=n[b];
else if(n[b]==0&&n[a]!=0)
n[b]=n[a];
else if(n[b]!=n[a])
{ int k=n[a];
for(j=1;j<x+1;j++)
if(n[j]==k)
n[j]=n[b];
i--;
}
else if(n[a]==0&&n[b]==0)
{
n[a]=i;
n[b]=i;
i++;
}
}
int c=0,l=0;
for(j=1;j<x+1;j++)
{
if(n[j]==0)
c++;
else
teamcount[n[j]]++;
}
int zero=c;
c=1;
for(j=1;j<i+1;j++)
if(teamcount[j]!=0)
c*=teamcount[j];
printf("%d %d\n",(i+zero-1),c);
}
return 0;
}