Link: Ultraviolet A 818-Cutting Chains
The following figure shows some links and links that are connected to each other. You can connect these rings at least when you open them. Note that they are not rings.
Solution: Because n is only 15 at the maximum, you can use a binary number to indicate whether each ring is opened, and then determine whether there is a location degree greater than 2, and whether there is a ring.
#include
#include
#include
#include using namespace std;const int N = 20;int n, ans, k, ti, g[N][N];void init() {ans = n;int a, b;memset(g, 0, sizeof(g));while (scanf("%d%d", &a, &b) == 2) {if (a == -1 || b == -1) break;g[a-1][b-1] = g[b-1][a-1] = 1;}}int cal(int s) {return s ? cal(s/2) + (s&1) : 0;}bool judge() {for (int i = 0; i < n; i++) {if (k & (1<
2) return true;}return false;}bool dfs(int f, int u, int* vis) {if (vis[u]) return true;vis[u] = 1;for (int i = 0; i < n; i++) {if (k & (1<
= ti - 1) {ans = min(ans, cal(k));}}int main() {int cas = 1;while (scanf("%d", &n) == 1 && n) {init();for (k = 0; k < (1<