c++
1#include <iostream>
2#include <map>
3#include <vector>
4using namespace std;
5
6int bit_count(int x)
7{
8 int k;
9 for (k = 0; x; x &= x - 1) k++;
10 return k;
11}
12
13int main()
14{
15 int n, a, x, y, max = 0;
16 cin >> n;
17 vector<map<int, int>> v(n);
18 for (int i = 0; i < n; i++) {
19 cin >> a;
20 while (--a >= 0) {
21 cin >> x >> y;
22 v[i][x-1] = y; // map に証言を登録
23 }
24 }
25 for (int p = 1 << n; --p; ) { // ビットパターン全部を試す
26 bool ok = true; // このビットパターンに矛盾が無いと仮定
27 for (int i = 0; ok && i < n; i++)
28 if (p >> i & 1) // i番目の人が正直者なら
29 for (auto m : v[i]) // m は正直者の証言のひとつ
30 if ((p >> m.first & 1) != m.second) {
31 ok = false; // 矛盾が見つかった
32 break;
33 }
34 if (ok) { // 矛盾が無かったら
35 int k = bit_count(p);
36 if (k > max) max = k; // 正直者の最大数を更新n
37 }
38 }
39 cout << max << endl;
40}
map を知らなければ理解できないでしょう。
追記
map は必要ありませんでした。証言の vector で十分です。
c++
1#include <iostream>
2#include <vector>
3using namespace std;
4
5struct Testimony { // 証言
6 int x, y;
7 Testimony(int x, int y) : x(x), y(y) {}
8};
9
10int main()
11{
12 int n, a, x, y, max = 0;
13 cin >> n;
14 vector<vector<Testimony>> v(n);
15 for (int i = 0; i < n; i++) {
16 cin >> a;
17 while (--a >= 0) {
18 cin >> x >> y;
19 v[i].push_back(Testimony(x-1, y)); // vector に証言を追加
20 }
21 }
22 for (int p = 1 << n; --p; ) { // ビットパターン全部を試す
23 int k = 0; // 正直者の人数
24 bool ok = true; // このビットパターンに矛盾が無いと仮定
25 for (int i = 0; ok && i < n; i++)
26 if (p >> i & 1) { // i番目の人が正直者なら
27 k++;
28 for (auto& t : v[i]) // t は正直者の証言のひとつ
29 if ((p >> t.x & 1) != t.y) {
30 ok = false; // 矛盾が見つかった
31 break;
32 }
33 }
34 if (ok && k > max) max = k; // 正直者の最大数を更新n
35 }
36 cout << max << endl;
37}
bit_count関数も不要で、正直者の人数 k をカウントアップするだけで十分でした。
ところで、もっと詳しい解説は要らないのですか?