Problem:
Score : 300 points

Problem Statement

We have N switches with "on" and "off" state, and M bulbs. The switches are numbered 1 to N, and the bulbs are numbered 1 to M.

Bulb i is connected to k_i switches: Switch s_{i1}, s_{i2}, ..., and s_{ik_i}. It is lighted when the number of switches that are "on" among these switches is congruent to p_i modulo 2.

How many combinations of "on" and "off" states of the switches light all the bulbs?

Constraints

1 \leq N, M \leq 10

1 \leq k_i \leq N

1 \leq s_{ij} \leq N

s_{ia} \neq s_{ib} (a \neq b)

p_i is 0 or 1.

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N M
k_1 s_{11} s_{12} ... s_{1k_1}
:
k_M s_{M1} s_{M2} ... s_{Mk_M}
p_1 p_2 ... p_M

Output

Print the number of combinations of "on" and "off" states of the switches that light all the bulbs.

Sample Input 1

2 2
2 1 2
1 2
0 1

Sample Output 1

1

Bulb 1 is lighted when there is an even number of switches that are "on" among the following: Switch 1 and 2.

Bulb 2 is lighted when there is an odd number of switches that are "on" among the following: Switch 2.

There are four possible combinations of states of (Switch 1, Switch 2): (on, on), (on, off), (off, on) and (off, off). Among them, only (on, on) lights all the bulbs, so we should print 1.

Sample Input 2

2 3
2 1 2
1 1
1 2
0 0 1

Sample Output 2

0

Bulb 1 is lighted when there is an even number of switches that are "on" among the following: Switch 1 and 2.

Bulb 2 is lighted when there is an even number of switches that are "on" among the following: Switch 1.

Bulb 3 is lighted when there is an odd number of switches that are "on" among the following: Switch 2.

Switch 1 has to be "off" to light Bulb 2 and Switch 2 has to be "on" to light Bulb 3, but then Bulb 1 will not be lighted. Thus, there are no combinations of states of the switches that light all the bulbs, so we should print 0.

Sample Input 3

5 2
3 1 2 5
2 2 3
1 0

Sample Output 3

8

Solution in C++14 (GCC 5.4.1) (judge verdict: Wrong Answer)

#include <string>
#include <vector>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <map>
#include <queue>
#include <iostream>
#include <cstdio>
#include <set>

const double PI = acos(-1);
 
using namespace std;
typedef long long ll;
typedef long double ld;
 
const ll MOD=ll(1e9+7);
const ll INF = ll(1e18) + 7;
 
//repetition
#define REP(i,n)  for(ll i=0;i<n;i++)
#define RREP(i,n)  for(ll i=n;i != 0;i--)
 
ll gcd(ll a,ll b)
{
	if (a%b==0)
	{
		return(b);
    }
	else
	{
		return(gcd(b,a%b));
    }
}

unsigned GetDigit(unsigned num){
    unsigned digit=0;
    while(num!=0){
        num /= 10;
        digit++;
    }
    return digit;
}
 
unsigned binarySearch(ll target, ll max, ll min) {
  while((max - min) > 1) {
      if((max + min)/2 > target) {
        max = (max + min)/2;
        min = min;
      } else {
        max = max;
        min = (max + min)/2;
      }
    }
}
 
void f(int rest, string s) {
  char abc[] = "abc";
  if(rest == 0) {
    cout << s << endl;
  } else {
    for(int i=0; i < 3; i++) {
      f(rest - 1, s+abc[i]);
    }
  }
} 
 
 
 
// origin (ox, oy) destination (dx, dy)
//
/*
ll dfs2(ll ox, ll oy, vector<vector<char>> v, vector<vector<int>> dist) {
 
  int m = 0;
  for (int i = 0; i < 4; i++) {
    int nx = ox+dx[i], ny = oy + dy[i];
    if(nx < 0 || nx >= w || ny < 0 || nx >= h) continue;
    if(v[nx][ny] != '.') continue;
 
    if(dist[nx][ny] == -1) {
      dist[nx][ny] = dist[ox][oy] + 1;
 
      dist[nx][ny] = min(dist[ox][oy], dist[nx][ny]);
 
      cout << "v[nx][ny]: " << dist[nx][ny] << endl;
      cout << "dx: " << dx << endl;
      cout << "dy: " << dy << endl;
      cout << "v[ox][oy]: " << v[ox][oy] << endl;
      cout << "(nx, ny)" << "("<< nx << "," << ny << ")"<< endl;
      dfs2(nx, ny, v, dist);
    }
    m = max(m, dist[nx][ny]);
  }
  return m;
}
 
int main() {
  // n,m->size, k-> value
  // vector<vector<ll>> a(n ,vector<ll>(m, k));
  // vector
  // vector<ll> s(n,0);
  // vector<vector<ll>> v;
  // map<ll,ll> m;
  // priority_queue<pair<ll, ll>, vector<pair<ll, ll>>, greater<pair<ll, ll>>> pq;
  // vector<pair<ll, ll>> epv(n, {0, 0});
  // vector<vector<char>> v(h, vector<char>(w));
  
  for(auto&& m: em) {
    epv.push_back({ m.second, m.first });
  }
 
  ll n, k, a;
  cin >> n >> k;
 
  vector<ll> vp;
  vector<ll> vn;
 
  ll c = 0;
 
  REP(i, n) {
    cin >> a;
    if(a >= 0 ) vp.push_back(a);
    else vn.push_back(a);
  }
 
  sort(vp.begin(), vp.end());
  sort(vn.begin(), vn.end());
 
  ll ps = vp.size();
  ll ns = vn.size();
 
  cout << "k: " << k << endl;
  cout << "ps: " << ps << endl;
  cout << "ns: " << ns << endl;
 
  if(k < ps * ns) {
    ll m = k%ns;
    ll d = k - (m+1);
    cout << vn[m] * vp[d] << endl;
 
  }else {
    ll kd = k - ps*ns;
    ll md = kd%ps;
    ll dd = kd - md;
 
 
    ll s = 0;
    REP(i, ps) {
      s = s+(ps-i-1);
      cout << "s: " << s << endl;
      cout << "kd: " << kd << endl;
      cout << "s: " << s << endl;
      cout << "kd: " << kd << endl;
      cout << "i: " << i << endl;
      if(s > kd) {
        cout << "vp[i]: " << vp[i] << endl;
        cout << "vp[ps-i]: " << vp[s-kd+i-1] << endl;
        cout << vp[i] * vp[s-kd+i-1] << endl;
        break;
      }
    }
  }
 
}
 
 
ll h, w;
vector<vector<char>> v;
 
vector<ll> dx = {-1, 0, 1, 0};
vector<ll> dy = {0, -1, 0, 1};
 
ll bfs(ll ox, ll oy) {
  vector<vector<ll>> vd(h, vector<ll>(w, -1));
  queue<pair<ll, ll>> q;
  q.push({ox, oy});
  vd[oy][ox] = 0;
 
  ll res = 0;
  while(!q.empty()) {
    pair<ll, ll> vn = q.front();
    q.pop();
    res = max(res, vd[vn.second][vn.first]);
 
    for(ll i = 0; i < 4; i++){
      ll nx = vn.first +dx[i];
      ll ny = vn.second + dy[i];
 
      if(nx < 0 || ny < 0 || nx >= w || ny >= h) continue;
      if(v[ny][nx] == '#') continue;
      if(vd[ny][nx] == -1) {
        vd[ny][nx] = res + 1;
        q.push({nx, ny});
      }
    }
  }
  return res;
}
 
bool kai(string s) {
   bool flg = true;
   ll n = s.size();
   for(ll i=0; i<n/2; i++) {
     if(s[i] == s[n-1 -i]){
       flg = true;
     } else {
       flg = false;
       break;
     }
   }
 
   return flg;
}
*/

struct UnionFind {
  vector<ll> par;
  map<ll, ll> s;

  UnionFind(ll n) : par(n) {
    REP(i, n) {
      par[i] = i;
      s[i]++;
    }
  }

  ll root(ll x) {
    if(par[x] == x) return x;
    return root(par[x]);
  }

  void unite(ll x, ll y) {
    ll rx = root(x);
    ll ry = root(y);
    if(rx == ry) return;

    if(size(rx) > size(ry)) {
      s[rx] = s[rx] + s[ry];
      par[root(y)] = rx;
    } else {
      s[ry] = s[ry] + s[rx];
      par[root(x)] = ry;
    }
  }

  bool same(ll x , ll y) {
    return root(x) == root(y);
  }

  ll size(ll x) {
    return s[root(x)];
  }
};
 
ll mod_pow(ll base, ll exp) {
  if(exp == 1) return base%MOD;
  if(exp%2 == 1) return (base*mod_pow(base, exp-1))%MOD;
  ll t = mod_pow(base, exp/2);
  return (t*t)%MOD;
}

// nPr
ll mod_permutation(ll n, ll r) {
  ll t = 1;
  while(r != 0){
    t = (t%MOD) * (n%MOD);
    n--;
    r--;
  }
  return t;
}

ll mod_factorial(ll r) {
  ll v = 1;
  while(r != 0){
    v= (v%MOD) * (r%MOD);
    r--;
  }
  return v;
}

struct Node {
  vector<ll> edges;
  vector<ll> costs;
  bool done;
  ll cost;

  friend bool operator<(const Node& lhs, const Node& rhs){ return rhs.cost < lhs.cost; }
};

ll mod_conb() {
  //((p%MOD)*(mod_pow(k, MOD-2)%MOD)*(mod_pow(ki, MOD-2)%MOD))%MOD
}

int main() {
  ll n,m;
  cin >> n >> m;

  ll k;
  ll s;

  vector<vector<ll>> sk;

  vector<bool> p;

  REP(i, m) {
    cin >> k;
    vector<ll> sm(n, 0);
    REP(j, k) {
      cin >> s;
      sm[s-1] = 1;
    }
    sk.push_back(sm);
  }

  bool pi;
  REP(i, m) {
    cin >> pi;
    p.push_back(pi);
  }

  ll ma = 0;
  for(ll bit =0; bit < (1<<n); bit++) {
    ll ok = true;
    REP(i, m) {
      ll c = 0;
      REP(j, m) {
        if(bit & (1 << j)) {
          if(sk[i][j]) c++;
        }
      }
      if(c%2 != p[i]) ok = false;
    }
    if(ok) ma++;
  }
  cout << ma;
  return 0;
}