乱七八糟
// 八皇后
int ANS[8], y[8]; bool xie1[16], xie2[16]; int dfs(int line) { int ans = 0; if (line == 8) return 1; for (int i = 0 ; i < 8 ; i ++){ if (y[i] || xie1[line - i + 7] || xie2[line + i]) continue; ANS[line] = i; y[i] = xie1[line - i + 7] = xie2[line + i] = true; ans += dfs(line + 1); y[i] = xie1[line - i + 7] = xie2[line + i] = false; } return ans; }
// 边表 struct Edge{ int to, value, pre; Edge(int _to, int _value, int _pre):to(_to), value(_value), pre(_pre){} }; Edge edges[MAX << 1]; int edgePos; int edgeHead; void edgeInit() { int edgePos = 0; memset(edgeHead, -1, sizeof edgeHead); } void addEdge(int s, int to, int value) { edge[edgePos] = Edge(to, value, edgeHead[s]); edgeHead[s] = edgePos ++; }