Untitled
raw download clone
CPP
views 17
,
size 2063 b
#include <bits/stdc++.h>
#define F first
#define S second
#define pb push_back
#define eb emplace_back
#define mkp make_pair
#define ms(a, b) memset(a, b, sizeof(a))
#define ALL(x) x.begin(), x.end()
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
constexpr ll MOD = 1e9 + 7;

int n, m;
vector<bitset<502>> matrix;
void print() {
    for(int i = 1; i <= n; ++i) {
        for(int j = 1; j <= m + 1; ++j)
            cout << matrix[i][j] << " ";
        cout << '\n';
    }
    cout << '\n';
}
bool check() {
    for(int cur = 1, i = 1; cur <= m;) {
        int tmp = i;
        while(tmp <= n && !matrix[tmp][cur])
            tmp++;
        if(tmp == n + 1) {
            cur++;  
            continue;
        }
        swap(matrix[tmp], matrix[i]);
        for(int j = i + 1; j <= n; ++j) if(matrix[j][cur])
            matrix[j] ^= matrix[i];
        //print();
        ++i;
    }
    for(int i = 1; i <= n; ++i) {
        if(!(matrix[i].count() - matrix[i][m + 1]) && matrix[i][m + 1])
            return false;
    }
    return true;
}

inline void solve() {
    cin >> n >> m;
    matrix.assign(n + 1, bitset<502>(0));
    string str; cin >> str;
    for(int i = 0; i < n; ++i) {
        matrix[i + 1][m + 1] = str[i] - '0';
    }
    for(int i = 1; i <= m; ++i) {
        int t; cin >> t;
        while(t--) {
            int tmp; cin >> tmp;
            matrix[tmp][i] = 1;
        }
    }
    //print();
    cout << (check() ? "yes" : "no") << '\n';
}

//#define IOFILE
int main() {
#ifndef IOFILE
    cin.tie(nullptr), cout.tie(nullptr), ios::sync_with_stdio(false);
#endif
#ifdef IOFILE
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
    freopen("err.txt", "w", stderr);
    clock_t time = clock();
#endif
    int t = 1;
    // cin >> t;
    while(t--) {
        solve();
    }

#ifdef IOFILE
    cout << "\nUse " << static_cast<double>(clock() - time) / CLOCKS_PER_SEC << " seconds";
#endif
}
close fullscreen
Login or Register to edit or fork this paste. It's free.