Long long ago, there was a prosperous kingdom which consisted of n cities and every two cites were connected by an undirected road.
However, one day a big monster attacked the kingdom and some roads were destroyed. In order to evaluate the influence brought by the catastrophe, the king wanted to know the instability of his kingdom. Instability is defined as the number of the unstable subset of {1, 2,⋯,n}.
A set S is unstable if and only if there exists a set A such that A⊆S(|A|≥3
) and A is a clique or an independent set, namely that cites in A are pairwise connected directly or they are pairwise disconnected.
Archaeologist has already restored themroads that were not destroyed by the monster. And they want you to figure out the instability.
Since the answer may be tremendously huge, you are only required to write a program that prints the answer modulo 1000000007.
Input
The first line contains only one integer T, which indicates the number of test cases.
For each test case, the first line contains two integers n (3≤n≤50) and m (1≤m≤n(n−1)/2
), indicating the number of cities and the number of roads.
Then the following are m lines, each of which contains two integers x and y, indicating there is a road between the city x and the city y.
It is guarenteed that there does not exist a road connecting the same city and there does not exist two same roads.
Output
For each test case, print a line “Case #x: y”, where x is the case number (starting from 1) and y is an integer indicating the instability modulo 1000000007.
Sample Input
2
4 3
1 2
2 3
1 3
3 0
Sample Output
Case #1: 2
Case #2: 1
Hint
• In the first example, {1,2,3} and {1,2,3,4} , containing the subset {1,2,3} which is connected
directly, are considered unstable.
• In the second example, {1,2,3} is considered unstable because they are not pairwise connected
directly.
题意:给出一个图,问稳定子图的个数,稳定子图的定义是至少由3个点两两先连或者两两不想连。
做法:找规律,超过5个点的子图必定是符合的,暴力枚举小于等于5个的子图。
#include<bits/stdc++.h>
using namespace std;
const int N = 55;
int num[N];
bool vis[N][N];
const int mod = 1e9+7;
void sub(long long &x){
x --;
if(x < 0)x += mod;
}
bool judge(int a,int b,int c){
return vis[a][b]&&vis[b][c]&&vis[a][c] || !vis[a][b]&&!vis[b][c]&&!vis[a][c];
}
bool judge(int a,int b,int c,int d){
return judge(a,b,c)||judge(b,c,d)||judge(a,c,d)||judge(a,b,d);
}
bool judge(int a,int b,int c,int d,int e){
return judge(b,c,d,e)||judge(a,c,d,e)||judge(a,b,d,e)||judge(a,b,c,e)||judge(a,b,c,d);
}
int main(){
int T;
cin >> T;
for(int kase = 1;kase <= T;kase ++){
int n,m;
scanf("%d %d",&n,&m);
memset(vis,false,sizeof(vis));
for(int i = 1;i <= m;i ++){
int a,b;
scanf("%d %d",&a,&b);
vis[a][b] = vis[b][a] = true;
}
long long ans = 1;
for(int i = 1;i <= n;i ++) ans = ans*2%mod;
for(int i = 1;i <= n;i ++)
for(int j = i+1;j <= n;j ++)
for(int k = j+1;k <= n;k ++) if(!judge(i,j,k)) sub(ans);
for(int i =1;i <= n;i ++)
for(int j =i+1;j <= n;j ++)
for(int k =j+1;k <= n;k ++)
for(int o =k+1;o <= n;o ++) if(!judge(i,j,k,o)) sub(ans);
for(int i =1;i <= n;i ++)
for(int j =i+1;j <= n;j ++)
for(int k =j+1;k <= n;k ++)
for(int o =k+1;o <= n;o ++)
for(int p =o+1;p <= n;p ++) if(!judge(i,j,k,o,p)) sub(ans);
//cout <<"!!!"<< ans << ' '<< n*(n-1)/2+n+1<< endl;
ans -= n*(n-1)/2+n+1;
if(ans < 0) ans += mod;
printf("Case #%d: %lld\n",kase,ans);
}
return 0;
}