3、id(int x, int y){ return x >= 0 && x < n1 && y >= 0 && y < n2;}void getGraph(){ for (int i = 0; i
4、col + diry[j]; if (!valid(x, y)) continue; graph[i][degree[i]++] = x * n2 + y; } deg[i] = degree[i]; }}void resume(int cur){ for (int i = 0; i < degree[cur]; ++i) { int next = graph[cur][i]; if (used[next]) continue; deg[
5、next]++; }}bool update(int cur){ bool ret = true; for (int i = 0; i < degree[cur]; ++i) { int next = graph[cur][i]; if (used[next]) continue; deg[next]--; if (deg[next] < 2 && next != graph[0][1]) ret = false; } if (!ret) { resume(cu
6、r); return false; } return true;}bool dfs(int step, int cur)//递归版{ ans[step] = cur; if (step == n - 1) { if (graph[0][1] != cur) return false; for (int i = 0; i
7、nt i = 0; i < degree[cur]; ++i) { if (cur == 0 && i) break; int next = graph[cur][i]; if (used[next]) continue; used[next] = true; if (!update(cur)) { used[next] = false; continue; } if (dfs(step + 1, next))