I thought about it for a long time. See the official puzzle will ...
Bond is a small cut-edge set that , after removing a bond, only divides the original into two connected blocks.
Assuming that some points constitute a set of S (a decimal number that is obtained after the point in the point set is pressed), then the remaining points constitute a set of t= (1<<n) -1-s
If s is connected and T is also connected, the answer to the edge of the set of S, T is +1 (that is, the edges across s and T sets form a bond).
Therefore, you simply enumerate S.
The next question turns into the following two questions:
1. How to determine whether a point set is connected: pressure DP pretreatment.
2. How to make a cross s, T set of the edge of the answer + 1: If each time traversing all sides to add the answer, time complexity explosion O (m* (1<<n)), therefore need to change a way of thinking:
We can figure out that all bond has several, and then subtract (U,V) the number of bond that does not cross s,t is (u,v) the answer of this side.
Specific look at the Code bar ~ ~, and then affixed the official puzzle:
#pragmaComment (linker, "/stack:1024000000,1024000000")#include<cstdio>#include<cstring>#include<cmath>#include<algorithm>#include<vector>#include<map>#include<Set>#include<queue>#include<stack>#include<iostream>using namespaceStd;typedefLong LongLL;Const DoublePi=acos (-1.0), eps=1e-8;voidFile () {freopen ("D:\\in.txt","R", stdin); Freopen ("D:\\out.txt","W", stdout);} InlineintRead () {Charc = GetChar (); while(!isdigit (c)) C =GetChar (); intx =0; while(IsDigit (c)) {x = x *Ten+ C-'0'; c =GetChar ();} returnx;}intt,n,m,e[ -],sum[(1<< -)+Ten],sz;intu[ -],v[ -];BOOLf[(1<< -)+Ten];voidPre () { for(intI=0; i<n;i++) f[1<<i]=1; for(intI=0;i< (1<<N); i++) { if(!f[i])Continue; intst=0; for(intj=0; j<n;j++)if(i& (1<<J)) st=st|E[j]; for(intj=0; j<n;j++) { if(i& (1<<J))Continue; if(st& (1<<J)) f[i| (1<<J)]=1; } }}intMain () {scanf ("%d", &t);intcas=1; while(t--) {scanf ("%d%d",&n,&m); memset (E,sz=0,sizeofe); Memset (F,0,sizeoff); memset (SUM,0,sizeofsum); for(intI=0; i<m;i++) {scanf ("%d%d",&u[i],&V[i]); E[u[i]]=e[u[i]]| (1<<v[i]), e[v[i]]=e[v[i]]| (1<<U[i]); } pre (); for(intI=0;i< (1<<N); i++) { if(f[i]==0|| f[(1<<n)-1-i]==0)Continue; if(I> (1<<n)-1-I.) Break; Sum[i]=1; sum[(1<<n)-1-i]=1; sz++; } for(intI=0; i<n;i++) { for(intJ= (1<<n)-1; j>=0; j--) { if((1<<i) &j)Continue; SUM[J]=sum[j]+sum[(1<<i) |J]; }} printf ("Case #%d:", cas++); for(intI=0; i<m;i++) printf ("%d", sz-sum[(1<<u[i]) | (1<<V[i]); printf ("\ n"); } return 0;}
HDU 5765 Bonds