QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#64789#997. 2-SAT 问题zhoukangyang#WA 31ms8972kbC++111.4kb2022-11-25 16:13:312022-11-25 16:13:34

Judging History

你现在查看的是最新测评结果

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-11-25 16:13:34]
  • 评测
  • 测评结果:WA
  • 用时:31ms
  • 内存:8972kb
  • [2022-11-25 16:13:31]
  • 提交

answer

#include<bits/stdc++.h>
#define L(i, j, k) for(int i = (j); i <= (k); ++i) 
#define R(i, j, k) for(int i = (j); i >= (k); --i) 
#define ll long long 
#define vi vector < int > 
#define sz(a) ((int) (a).size()) 
#define me(a, x) memset(a, x, sizeof(a)) 
#define ull unsigned long long 
using namespace std;
const int N = 1e6 + 7, inf = 1e7;
int n, m;
int ehd[N], ev[N], enx[N], eid;
void eadd(int u, int v) {
	++eid, ev[eid] = v, enx[eid] = ehd[u], ehd[u] = eid;
}

int dfn[N], low[N], idt, qid[N], cnt;

int stk[N], tp;
bool vis[N];
 
void dfs(int x) {
	dfn[x] = low[x] = ++idt, vis[x] = true, stk[++tp] = x;
	for(int i = ehd[x]; i; i = enx[i]) {
		if(!dfn[ev[i]]) dfs(ev[i]), low[x] = min(low[x], low[ev[i]]);
		else if(vis[ev[i]]) low[x] = min(low[x], dfn[ev[i]]);
	}
	if(dfn[x] == low[x]) {
		++cnt;
		for(int u = 0; u != x; --tp) 
			u = stk[tp], qid[u] = cnt, vis[u] = false;
	} 
} 

int main() {
	ios :: sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	cin >> n >> m;
	L(i, 1, m) {
		int a, b, c, d;
		cin >> a >> b >> c >> d, b ^= 1;
		eadd(a + b * n, c + d * n);
		eadd(c + (d ^ 1) * n, a + (b ^ 1) * n);
	}
	
	L(i, 1, n * 2) if(!dfn[i]) dfs(i);
	
	L(i, 1, n) 
		if(qid[i] == qid[i + n]) {
			cout << "No\n";
			return 0;
		}
	cout << "Yes\n";
	L(i, 1, n) 
		if(qid[i] < qid[i + n]) cout << 1 << ' ';
		else cout << 0 << ' ';
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 31ms
memory: 8972kb

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
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...

result:

wrong answer Your plan didn't satisfy condition #1.(i = 14615, a = 0, j = 14903, b = 1)