Test instructions is to give a picture, remove some of the nodes, and then linked to a chain, ask at least a few nodes removed.
N is very small n<=15, so it is OK to enumerate 2^15 states directly.
The condition of the chain is 1. No ring, 2. The point with no degree greater than 2, 3. To connect n a loose chain needs n-1 times splicing, remove the node >=n-1.
#include <bits/stdc++.h>using namespacestd;Const intMAXN = the;intG[MAXN][MAXN];intN;intC[MAXN];BOOLDfsintUintSintFA) {C[u]=1; for(intv =0; v < n; v++)if(! ((S>>V) &1) && G[u][v] && v! =FA) { if(C[v] | | DFS (V,S,U))return true; } return false;}intcn;BOOLHave_circle (ints) {memset (c,0,sizeof(c)); for(inti =0; i < n; i++) if(! ((s>>i) &1) &&!C[i]) {CN++; if(Dfs (i,s,-1))return true; } return false;}BOOLBoth (ints) { for(inti =0; I < n; i++)if(! ((s>>i) &1)) { intdeg =0; for(intj =0; J < N; J + +)if(! ((S>>J) &1) &&G[i][j]) {deg++; } if(deg>2)return true; } return false;}intCalintSint&6) {T=0; while(s) {if(s&1) t++; S>>=1; } returnt;}intMain () {//freopen ("In.txt", "R", stdin); intCAS =0; while(~SCANF ("%d", &n) &&N) { intu,v; memset (G,0,sizeof(G)); while(~SCANF ("%d%d", &u,&v) &~T) {G[u-1][v-1] = g[v-1][u-1] =1; } intAns =233; for(ints =0, Sz =1<<n; s < sz; s++) {cn=0; if(!two (s) &&!have_circle (s)) { intT; if(cn-1<=cal (S,t)) ans=min (ans,t); }} printf ("Set%d:minimum links to open is%d\n", ++cas, ans); } return 0;}
UVA 818 Cutting Chains