func_code_string: #include <bits/stdc++.h>   template <class C, class E>   inline bool contains(const C &container, const E &element) {     return container.find(element) != container.end();   }   template <class T>   inline void checkmin(T &a, T b) {     if (b < a) a = b;   }   template <class T>   inline void checkmax(T &a, T b) {     if (b > a) a = b;   }   using namespace std;   map<int, bool> res;   enum Type { XOR, AND, IN, NOT, OR };   struct Gate {     Type _type;     int _index;     bool _bOriVal;     int _c[2];   };   vector<Gate> gates;   bool Eval(int index) {     Gate &g = gates[index];     bool bRes;     switch (g._type) {       case OR: {         bool b1 = Eval(g._c[0]);         bool b2 = Eval(g._c[1]);         bRes = b1 || b2;       } break;       case AND: {         bool b1 = Eval(g._c[0]);         bool b2 = Eval(g._c[1]);         bRes = b1 && b2;       } break;       case NOT:         bRes = !Eval(g._c[0]);         break;       case XOR:         bRes = Eval(g._c[0]) != Eval(g._c[1]);         break;       case IN:         bRes = g._bOriVal;         break;     }     g._bOriVal = bRes;     return bRes;   }   void Solve(int index, bool resObt[2]) {     Gate &g = gates[index];     switch (g._type) {       case OR: {         for (int i = 0; i < 2; ++i) {           int askedSubGate = g._c[i];           int otherSubGate = g._c[1 - i];           bool otherSubVal = gates[otherSubGate]._bOriVal;           bool rr[2];           rr[false] = resObt[otherSubVal || false];           rr[true] = resObt[otherSubVal || true];           Solve(askedSubGate, rr);         }         break;       }       case AND:         for (int i = 0; i < 2; ++i) {           int askedSubGate = g._c[i];           int otherSubGate = g._c[1 - i];           bool otherSubVal = gates[otherSubGate]._bOriVal;           bool rr[2];           rr[false] = resObt[otherSubVal && false];           rr[true] = resObt[otherSubVal && true];           Solve(askedSubGate, rr);         }         break;       case NOT: {         bool rr[2];         rr[0] = resObt[1];         rr[1] = resObt[0];         Solve(g._c[0], rr);         break;       }       case XOR: {         for (int i = 0; i < 2; ++i) {           int askedSubGate = g._c[i];           int otherSubGate = g._c[1 - i];           bool otherSubVal = gates[otherSubGate]._bOriVal;           bool rr[2];           rr[false] = resObt[otherSubVal != false];           rr[true] = resObt[otherSubVal != true];           Solve(askedSubGate, rr);         }         break;       }       case IN: {         res[g._index] = resObt[!g._bOriVal];         break;       }     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     cout << std::setprecision(15);     cout << std::fixed;     int n;     cin >> n;     gates.resize(n + 1);     for (int i = (1), _b = (n); i <= _b; i++) {       string s;       cin >> s;       if (s ==  IN ) {         gates[i]._type = IN;         bool val;         cin >> val;         gates[i]._bOriVal = val;         gates[i]._index = i;       } else if (s ==  AND ) {         gates[i]._type = AND;         cin >> gates[i]._c[0] >> gates[i]._c[1];       } else if (s ==  OR ) {         gates[i]._type = OR;         cin >> gates[i]._c[0] >> gates[i]._c[1];       } else if (s ==  XOR ) {         gates[i]._type = XOR;         cin >> gates[i]._c[0] >> gates[i]._c[1];       } else if (s ==  NOT ) {         gates[i]._type = NOT;         cin >> gates[i]._c[0];       }     }     bool current = Eval(1);     bool rr[2] = {false, true};     Solve(1, rr);     for (auto &v : res) {       cout << (v.second ?  1  :  0 );     }     return 0;   }   