classEdge { public: uint v; int p; Edge(uint v = 0, int p = 0) : v(v), p(p) {} } E[N];
intdp(uint sta);
std::unordered_map<uint, int> mp; int eid; int n, m;
intmain(){ read(n), read(m); for (int i = 1; i <= m; ++i) { int op, a, b; read(op), read(a), read(b); --a, --b; int id1 = (1u << a) | (1u << (b + n)); E[++eid] = Edge(id1, iv2); if (op == 0) { continue; } read(a), read(b); --a, --b; int id2 = (1u << a) | (1u << (b + n)); E[++eid] = Edge(id2, iv2); if (id1 & id2) { continue; } E[++eid] = Edge(id1 | id2, op == 1 ? iv4 : (Mod - iv4)); } write(dp((1u << (n << 1)) - 1) * 1ll * (1 << n) % Mod), EL; return0; }
intdp(uint sta){ if (!sta) { return1; } auto it = mp.find(sta); if (it != mp.end()) { return it->second; } int res = 0; for (int i = 1; i <= eid; ++i) { uint id = E[i].v; if ((id & sta) == id && (id << 1) > sta) { res = (res + E[i].p * 1ll * dp(sta ^ id)) % Mod; } } return mp[sta] = res; }