1528 {
1529 int maximum = 0;
1530 bool contradict = false;
1531 while(!que.empty()) {
1532 auto current = que.front();
1533 que.pop();
1534 if(um.contains(current.person)) {
1535
1536 if(um[current.person] != current.good) {
1537
1538 return pair<int, unordered_map<int, bool>>(0, {});
1539 }
1540 } else {
1541 um.insert(pair(current.person, current.good));
1542 }
1543 if(current.good) {
1544
1545 for(int j = 0; j < statements.size(); j++) {
1546 if(statements[current.person][j] != 2 && j != current.person) {
1547 auto nmsg = msg(j, statements[current.person][j] == 1);
1548 if(um.contains(nmsg.person)) {
1549
1550 if(um[nmsg.person] != nmsg.good) {
1551
1552 contradict = true;
1553 return pair<int, unordered_map<int, bool>>(0, {});
1554 }
1555 } else {
1556
1557 que.push(nmsg);
1558 }
1559 }
1560 }
1561 }
1562 }
1563 if(!contradict) {
1564
1565 auto dup = unordered_map<int, bool>();
1566 for(int i = 0; i < statements.size(); i++) {
1567 if(dup[i]) {
1568 continue;
1569 }
1570 if(!um.contains(i)) {
1571 bool all2 = true;
1572 for(auto v: statements[i]) {
1573 if(v != 2) {
1574 all2 = false;
1575 }
1576 }
1577 if(all2) {
1578 um.insert(pair(i, true));
1579 continue;
1580 }
1581 auto nque = queue<msg>();
1582 nque.push(msg(i, true));
1583 auto ans =
dfs(statements, um, nque);
1584 maximum = max(maximum,
ans.first);
1585 for(
auto it:
ans.second) {
1586 if(it.second) {
1587 dup.insert(it);
1588 }
1589 }
1590 }
1591 }
1592
1593 int good_count = 0;
1594 for(auto i: um) {
1595 if(i.second) {
1596 good_count++;
1597 }
1598 }
1599 maximum = max(maximum, good_count);
1600 }
1601 return pair(maximum, um);
1602 }
vector< vector< int > > ans
static pair< int, unordered_map< int, bool > > dfs(vector< vector< int > > &statements, unordered_map< int, bool > um, queue< msg > que)