DFS should be use to search answer.But I'm not good at DFS,So I use many times to debug my program.So sad.
The number of subset don't over 4,Because If the subsets contains 5 or even bigger,It must be have cross.
First I think the depth of the subset shouble be use.But finally I think It not useful.It's just a unuseful way to reduce the search numbers.
The portal:http://acm.hdu.edu.cn/showproblem.php?pid=5277
#include <stdio.h>
#include <string.h>
int f[1005][1005];
int temp[1005];
int templen;
int n,m;
int cnt3,cnt4;
int test(int k){
int i;
for(i=0;temp[i];i++){
if(f[temp[i]][k] == 0)
return 0;
}
temp[i] = k;
templen ++;
return 1;
}
void dfs(int s,int c,int si){
if(c == 3) cnt3 ++;
if(c == 4) cnt4 ++;
for(int i=si;i<=n;i++){
if(f[s][i]){
if(test(i)){
dfs(s,c+1,i+1);
temp[templen-1] = 0;
templen --;
}
}
}
}
void Deal_with(){
cnt3 = 0;cnt4 = 0;
for(int i=1;i<=n;i++){
memset(temp,0,sizeof(temp));
temp[0] = i;
templen = 1;
dfs(i,1,i+1);
}
if(cnt4){
printf("4 %d\n",cnt4);
return ;
}
if(cnt3){
printf("3 %d\n",cnt3);
return ;
}
if(m == 0){
printf("1 %d\n",n);
return ;
}
printf("2 %d\n",m);
}
int main(void){
//freopen("a.in","r",stdin);
//freopen("a.out","w",stdout);
while(~scanf("%d %d",&n,&m)){
memset(f,0,sizeof(f));
for(int i=0;i<n;i++){
int tempa,tempb;
scanf("%d %d",&tempa,&tempb);
}
for(int i=0;i<m;i++){
int tempa,tempb;
scanf("%d %d",&tempa,&tempb);
f[tempa][tempb] = 1;
f[tempb][tempa] = 1;
}
Deal_with();
}
return 0;
}