#include"bits/stdc++.h"
using namespace std;
int father[8];
int e[8][8];
int use[8];
int ans=0;
void init()//对无向图进行初始化
{
e[1][2]=e[1][6]=1;
e[2][1]=e[2][7]=e[2][3]=1;
e[3][2]=e[3][4]=e[3][7]=1;
e[4][3]=e[4][5]=1;
e[5][4]=e[5][6]=e[5][7]=1;
e[6][1]=e[6][5]=e[6][7]=1;
}
int find(int a)//使用并查集,查找有几个不同的根
{
if(father[a]==a)return a;
father[a]=find(father[a]);
return father[a];
}
void init_father(){
for(int i=1;i<=7;i++)father[i]=i;
}
void dfs(int u)
{
if(u==8){
int sum=0;
init_father();
for(int i=1;i<=7;i++)
for(int j=1;j<=7;j++){
if(e[i][j]&&use[i]&&use[j]){
int ti=find(i);
int tj=find(j);
if(ti!=tj){//if从i可以到j,并且i亮j也亮则,让father[ti]存入tj(相当于使father的根是j);
father[ti]=tj;
}
}
}
for(int i=1;i<=7;i++){
if(use[i]&&father[i]==i)sum++;
}
if(sum==1)ans++;
return;
}
use[u]=1;
dfs(u+1);
use[u]=0;
dfs(u+1);
}
int main()
{
init();
dfs(1);
cout<<ans;
}
此行路漫漫,与君共力勉;