QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#920410#997. 2-SAT 问题Poetry#WA 48ms13508kbC++261.3kb2025-02-28 15:52:152025-02-28 15:52:19

Judging History

This is the latest submission verdict.

  • [2025-02-28 15:52:19]
  • Judged
  • Verdict: WA
  • Time: 48ms
  • Memory: 13508kb
  • [2025-02-28 15:52:15]
  • Submitted

answer

#include <bits/stdc++.h>

using u32 = unsigned;
using i64 = long long;
using u64 = unsigned long long;

constexpr int N = 2E5 + 5;

int n, m;
int p[N], scc;

std::vector<int> adj[N];

std::stack<int> st;
int dfn[N], low[N], tot;
bool vis[N];

void dfs(int x) {
	dfn[x] = low[x] = ++tot;
	vis[x] = 1; st.push(x);
	for (auto y : adj[x]) {
		if (!dfn[y]) {
			dfs(y);
			low[x] = std::min(low[x], low[y]);
		}
		if (vis[y]) {
			low[x] = std::min(low[x], dfn[y]);
		}
	}
	if (low[x] == dfn[x]) {
		++scc;
		for (int i = 0; i != x; st.pop()) {
			i = st.top();
			p[i] = scc;
			vis[i] = 0;
			if (i == x) break;
		}
	}
}

int main() {
	std::ios::sync_with_stdio(false);
	std::cin.tie(nullptr);

	//a -> a = 0, a + n -> a = 1
	//a = [p[a + n] < p[a]]

	std::cin >> n >> m;
	for (int i = 1; i <= m; ++i) {
		int a, b, c, d;
		std::cin >> a >> b >> c >> d;
		adj[a + n * (b ^ 1)].push_back(c + n * (d & 1));
		adj[c + n * (d ^ 1)].push_back(a + n * (b & 1));
	}

	for (int i = 1; i <= 2 * n; ++i)
		if (!dfn[i]) dfs(i);

	for (int i = 1; i <= n; ++i)
		if (p[i] == p[i + n]) {
			std::cout << "No\n";
			return 0;
		}

	std::cout << "Yes\n";
	for (int i = 1; i <= n; ++i) {
		std::cout << (p[i + n] < p[i]) << " \n"[i == n];
	}

	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 30ms
memory: 13508kb

input:

86354 86418
14615 0 14903 1
13605 0 4458 0
15604 0 77112 0
52311 1 64996 0
22711 1 74245 1
39042 1 57372 1
2994 1 84183 1
80574 0 58791 1
27780 1 9336 1
61809 0 7216 0
71113 0 42287 1
20073 0 72448 0
73840 0 77048 0
28955 0 4165 0
16322 1 14075 1
43512 0 58600 1
45219 0 53858 0
14919 0 22576 0
16594...

output:

Yes
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...

result:

ok Good plan

Test #2:

score: -100
Wrong Answer
time: 48ms
memory: 10568kb

input:

17625 186889
17290 0 17616 1
8909 0 15829 0
9807 0 9920 1
14912 0 3052 1
14426 0 16910 1
8910 1 10153 1
5163 1 1118 1
2764 0 2787 1
2998 0 2344 1
17573 1 5693 1
9120 0 4529 1
9836 0 4832 0
4021 0 16206 1
1109 0 13286 1
12402 1 16982 0
6311 1 1218 1
147 0 5411 0
3958 1 1571 0
4848 1 16678 0
7433 1 31...

output:

No

result:

wrong answer You didn't find a solution but jury did.