int n, m, top; vector<int> g[MAXN * 2]; array<int, MAXN * 2> mark, stk;
voidadd(int u, int v){ g[u].emplace_back(v); }
voidinit(){ for (int i = 0; i < 2 * n; i++) g[i].clear(); fill(mark.begin(), mark.end(), 0); }
booldfs(int cur){ // 将 current 标记为 true if (mark[cur ^ 1]) returnfalse; if (mark[cur]) returntrue; mark[cur] = true; stk[top++] = cur; for (auto& to : g[cur]) if (!dfs(to)) returnfalse; returntrue; }
boolsolve(){ for (int i = 0; i < 2 * n; i += 2) { if (!mark[i] && !mark[i ^ 1]) { top = 0; if (!dfs(i)) { while (top > 0) mark[stk[--top]] = false; if (!dfs(i + 1)) returnfalse; } } } returntrue; }
intmain(){ boost; while (cin >> n >> m) { init(); for (int i = 1, a, b; i <= m; i++) { cin >> a >> b; a--, b--; add(a, b ^ 1); // !a | !b add(b, a ^ 1); } if (!solve()) { cout << "NIE\n"; } else { for (int i = 0; i < 2 * n; i++) if (mark[i]) cout << i + 1 << "\n"; } } return0; }
int n, m, tot, top, cntscc; vector<int> g[MAXN * 2]; int dfn[MAXN * 2], low[MAXN * 2], stk[MAXN * 2], ins[MAXN * 2], belong[MAXN * 2], ans[MAXN];
voidadd(int u, int v){ g[u].emplace_back(v); }
voidtarjan(int cur){ dfn[cur] = low[cur] = ++tot; stk[++top] = cur, ins[cur] = true; for (constauto& to : g[cur]) { if (!dfn[to]) { tarjan(to); low[cur] = min(low[cur], low[to]); } elseif (ins[to]) { low[cur] = min(low[cur], dfn[to]); } } if (dfn[cur] == low[cur]) { ++cntscc; int tmp; do { tmp = stk[top--]; ins[tmp] = false; belong[tmp] = cntscc; } while (cur != tmp); } }
intmain(){ boost; cin >> n >> m; string type; for (int t = 1; t <= m; t++) { int a, b, c; cin >> a >> b >> c >> type; a++, b++; if (type == "AND") { if (c == 0) add(a, b + n), add(b, a + n); else add(a + n, a), add(b + n, b); } elseif (type == "OR") { if (c == 0) add(a, a + n), add(b, b + n); else add(a + n, b), add(b + n, a); } else { if (c == 0) add(a, b), add(b, a), add(a + n, b + n), add(b + n, a + n); else add(a, b + n), add(b, a + n), add(b + n, a), add(a + n, b); } } for (int i = 1; i <= 2 * n; i++) if (!dfn[i]) tarjan(i); for (int i = 1; i <= n; i++) if (belong[i] == belong[i + n]) { cout << "NO" << "\n"; return0; } cout << "YES" << "\n"; return0; }
int n, m, tot, top, cntscc; vector<int> g[MAXN * 2]; int dfn[MAXN * 2], low[MAXN * 2], stk[MAXN * 2], ins[MAXN * 2], belong[MAXN * 2]; char ans[MAXN];
voidadd(int u, int v){ g[u].emplace_back(v); }
voidtarjan(int cur){ dfn[cur] = low[cur] = ++tot; stk[++top] = cur, ins[cur] = true; for (constauto& to : g[cur]) { if (!dfn[to]) { tarjan(to); low[cur] = min(low[cur], low[to]); } elseif (ins[to]) { low[cur] = min(low[cur], dfn[to]); } } if (dfn[cur] == low[cur]) { ++cntscc; int tmp; do { tmp = stk[top--]; ins[tmp] = false; belong[tmp] = cntscc; } while (cur != tmp); } }
intmain(){ boost; cin >> n >> m; string c[3]; int l[3], p[3]; for (int t = 1; t <= m; t++) { // 一个人猜 3 盏灯 a b c颜色 0/1,猜对至少 2 个则可满足 for (int i = 0; i < 3; i++) cin >> l[i] >> c[i], p[i] = c[i] == "R" ? 1 : 0;