我是靠谱客的博主 美满白昼,这篇文章主要介绍A Simple Task,现在分享给大家,希望可以做个参考。

题目链接 cf #11D

复制代码
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
#include<cstdio> #include<iostream> #include<algorithm> using namespace std; typedef long long ll; ll dp[1<<20][20]; int v[20][20]; int main() { ll ans=0; int m,n; cin>>n>>m; while(m--) { int x,y; cin>>x>>y; x--,y--; v[x][y]=v[y][x]=1; } for(int i=0;i<n;i++) dp[1<<i][i]=1; for(int s=1;s<(1<<n);s++) { int st; for(int i=0;i<n;i++) if((1<<i)&s) {st=i;break;}//找到s当中的第一个点 for(int e=st;e<n;e++)//枚举s状态中每一个可能在末尾的点 { if(!((1<<e)&s)) continue;//找到s中的点e for(int j=st;j<n;j++)//新收进来的点必须要在st的后面,以保证st是状态中的第一个点 { if((1<<j)&s) continue;//j不能是s中的点 if(v[j][e]) { dp[s|(1<<j)][j]+=dp[s][e];//你要想到,j是不会等于st的,不满足不属于s的条件,也就是说所有状态s,第一位是st,那么一定 if(v[st][j]&& __builtin_popcount(s|(1<<j))>=3) ans+=dp[s][e];//确实有可能e=st,但是上一句的遍历过程保证了dp[i][j]这个数组,当状态i的首位是st且i中包含两个以上点时,j一定不会是st,所以这里ans跟没加一样 } } } } cout<<ans/2<<endl; return 0; }

Given a simple graph, output the number of simple cycles in it. A simple cycle is a cycle with no repeated vertices or edges.

Input

The first line of input contains two integers n and m (1 ≤ n ≤ 190 ≤ m) – respectively the number of vertices and edges of the graph. Each of the subsequent m lines contains two integers a and b, (1 ≤ a, b ≤ na ≠ b) indicating that vertices a and b are connected by an undirected edge. There is no more than one edge connecting any pair of vertices.

Output

Output the number of cycles in the given graph.

Examples
Input
复制代码
1
2
3
4
5
6
7
4 6 1 2 1 3 1 4 2 3 2 4 3 4
Output
复制代码
1
7
Note

The example graph is a clique and contains four cycles of length 3 and three cycles of length 4.

最后

以上就是美满白昼最近收集整理的关于A Simple Task的全部内容,更多相关A内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(77)

评论列表共有 0 条评论

立即
投稿
返回
顶部