This is a creation in Article, where the information may have evolved or changed.
HDU 1824 let ' s go home
Topic links
Idea: Split the expression, a team split into A^b & A^c, and then build a map run 2-sat can
Code:
#include <cstdio> #include <cstring> #include <cstdlib> #include <vector> #include < algorithm>using namespace Std;const int maxnode = 3005;struct twoset {int n;vector<int> g[maxnode * 2];bool mark[ Maxnode * 2];int S[maxnode * 2], sn;void init (int tot) {n = tot * 2;for (int i = 0; i < n; i + = 2) {g[i].clear (); G[i^1] . Clear ();} Memset (Mark, False, sizeof);} void Add_edge (int u, int uval, int v, int vval) {u = u * 2 + uval;v = v * 2 + vval;g[u^1].push_back (v); G[v^1].push_back (U) ;} void Delete_edge (int u, int uval, int v, int vval) {u = u * 2 + uval;v = v * 2 + vval;g[u^1].pop_back (); G[v^1].pop_back (); }bool dfs (int u) {if (mark[u^1]) return false;if (Mark[u]) return true;mark[u] = true; s[sn++] = u;for (int i = 0; i < g[u].size (); i++) {int v = g[u][i];if (!dfs (v)) return false;} return true;} BOOL Solve () {for (int i = 0; i < n, i + = 2) {if (!mark[i] &&!mark[i + 1]) {sn = 0;if (!dfs (i)) {for (int j = 0) ; J < SN; J + +) Mark[s[j]] = FALSE;SN = 0;if (!dfs (i + 1)) return false;}}} return true;}} Gao;int N, m;int main () {while (~scanf ("%d%d", &n, &m)) {gao.init (n * 3); int A, B, C;while (n--) {scanf ("%d%d%d", &a, &b, &c); Gao.add_edge (A, 1, B, 1); Gao.add_edge (A, 1, c, 1);} while (m--) {scanf ("%d%d", &a, &b), Gao.add_edge (A, 0, B, 0), Gao.add_edge (A, 0, B, 0);} printf ("%s\n", Gao.solve ()? "Yes": "No");} return 0;}