-
Notifications
You must be signed in to change notification settings - Fork 62
/
Copy pathprefix_enlightenment.cpp
56 lines (45 loc) · 1.38 KB
/
prefix_enlightenment.cpp
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
// Problem: https://codeforces.com/problemset/problem/1290/C
#include <iostream>
#include <string>
#include <vector>
#include <cassert>
using namespace std;
// {{{ data_structures/union_find_bipartite }}}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int N, K;
cin >> N >> K;
string s;
cin >> s;
vector<vector<int>> switches(N);
for (int sw = 0; sw < K; sw++) {
int C;
cin >> C;
for (int i = 0; i < C; i++) {
int e;
cin >> e;
switches[e - 1].push_back(sw);
}
}
union_find_bipartite uf(K);
for (int lamp = 0; lamp < N; lamp++) {
switch (switches[lamp].size()) {
case 0:
assert(s[lamp] == '1');
break;
case 1:
assert(uf.can_constrain_node_to_side(switches[lamp][0], s[lamp] != '1'));
assert(uf.constrain_node_to_side(switches[lamp][0], s[lamp] != '1'));
break;
case 2:
assert(uf.can_add_constraint_on_nodes(switches[lamp][0], switches[lamp][1], s[lamp] != '1'));
assert(uf.unite(switches[lamp][0], switches[lamp][1], s[lamp] != '1').component_is_bipartite);
break;
default:
assert(false);
}
cout << uf.min_nodes_on_side_1 << "\n";
}
return 0;
}