HDU 4115 Eliminate the Conflict (2-sat), hdu2-sat

Source: Internet
Author: User

HDU 4115 Eliminate the Conflict (2-sat), hdu2-sat
HDU 4115 Eliminate the Conflict

Question Link

Alice and Bob are playing with scissors and stone cloths. They know what Bob is going to do in each round, and Bob gives Alice some restrictions. 1 indicates that Alice and I have to go out differently, 0 indicates that the results must be the same. If Alice loses in one game, the results will be "win". Ask Alice if she can win.

Idea: 2-sat. If Bob has something, Alice will either win or even, and then add m constraints to the question of 2-sat.

Code:

#include <cstdio>#include <cstring>#include <vector>using namespace std;const int N = 10005;int t, n, m, x[N], sn, S[N * 2];vector<int> g[N * 2];bool mark[N * 2];void init() {for (int i = 0; i < 2 * n; i++) g[i].clear();memset(mark, false, sizeof(mark));}void add_edge(int u, int x, int v, int y) {u = u * 2 + x;v = v * 2 + y;g[u^1].push_back(v);g[v^1].push_back(u);}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 < 2 * 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;}int main() {int cas = 0;scanf("%d", &t);while (t--) {init();scanf("%d%d", &n, &m);int tmp;for (int i = 0; i < n; i++)scanf("%d", &x[i]);int u, v, w;while (m--) {scanf("%d%d%d", &u, &v, &w);u--; v--;int tmp = 6 - x[u] - x[v];int a = 6 - x[u] - tmp;int b = 6 - x[v] - tmp;int u1, u2, v1, v2;u2 = a > tmp; u1 = !u2;v2 = b > tmp; v1 = !v2;if (w == 1) {if (x[u] == x[v]) {add_edge(u, 1, v, 1);add_edge(u, 0, v, 0);} else add_edge(u, !u1, v, !v1);} else {if (x[u] == x[v]) {add_edge(u, 0, v, 1);add_edge(u, 1, u, 0);} else {add_edge(u, u1, u, u1);add_edge(v, v1, v, v1);}}}printf("Case #%d: %s\n", ++cas, solve() ? "yes" : "no");}return 0;}



2 sat syntax questions (IE)

The following is my opinion, not necessarily true.

First, justify should be consistent with the following are tenses, while defend means that those should be different from justify.

The second question should be understandable. Africa's Kanem empire have fallen into decline when trade centers shift outsied its boundaries. It is obvious that shift has occurred in the past and should not be used normally in the present. This clause indicates that Africa's Kanem empire is considered to have declined as the trade center moved out of its territory. (The statement may not be fluent. Ignore it ). Its refers to empire, and shift is subject to centers.

Two SAT zhenti syntax questions (Please give me some advice and read other answers to this question clearly)

You can say yes, but you can see that the comparison objects are comparable. I have read some grammar books, like Zhang Yibing, I do my homework better than mary does. here, the does can be saved, and I want to correct it. This problem is not parallel, but comparable !! This is a parallel structure! For example, if the comparison is comparable, you can save the verb. In addition, your second sentence is also comparable. It is compared between few potes and ESVM. The third sentence can also be saved, as long as the object is comparable .. I didn't seem to make it clear .. There is also a comparable concept that people must be compared with people, and so on.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.