-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy path2SAT_problem.cpp
More file actions
86 lines (78 loc) · 1.69 KB
/
Copy path2SAT_problem.cpp
File metadata and controls
86 lines (78 loc) · 1.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
// Author : Apaar
// Built : 25-10-2019 00:48:00
// https://codeforces.com/contest/776/problem/D
#include<bits/stdc++.h>
using namespace std;
#define int long long int
#define ld long double
#define F first
#define S second
#define P pair<int,int>
#define pb push_back
#define db(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) { cout << name << " : " << arg1 << '\n'; }
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
const char* comma = strchr(names + 1, ',');
cout.write(names, comma - names) << " : " << arg1 << " | "; __f(comma + 1, args...);
}
const int N = 200005;
struct dsu {
vector<int> p, sz;
void init(int NN) {
sz.clear(); p.clear();
p.resize(NN); sz.resize(NN, 1);
iota(p.begin(), p.end(), 0);
}
int get(int x) {
return (x == p[x] ? x : (p[x] = get(p[x])));
}
void unite(int x, int y) {
x = get(x);
y = get(y);
if (sz[x] > sz[y]) {
swap(x, y);
}
if (x != y) {
p[x] = y;
sz[y] += sz[x];
sz[x] = 0;
}
}
} G;
vector<int> D[N];
int a[N];
int32_t main()
{
ios_base:: sync_with_stdio(false);
cin.tie(NULL); cout.tie(NULL);
// int t;cin>>t;while(t--)
{
int i, j, k, n, m, ans = 0, cnt = 0, sum = 0;
cin >> n >> m;
G.init(N);
for (i = 0; i < n; i++) {
cin >> a[i];
a[i] ^= 1;
}
for (i = 0; i < m; i++) {
cin >> k;
while (k--) {
int x;
cin >> x;
x--;
D[x].pb(i);
}
}
for (i = 0; i < n; i++) {
int u = D[i][0], v = D[i][1];
G.unite(2 * u, (2 * v) ^ a[i]);
G.unite(2 * u + 1, (2 * v + 1) ^ a[i]);
}
for (i = 0; i < m; i++) {
if (G.get(2 * i) == G.get(2 * i + 1)) return puts("NO"), 0;
}
puts("YES");
}
}