#include <bits/stdc++.h>   using namespace std;   mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());   int n, m;   vector<int> tr[1000005];   vector<int> vr[1000005];   pair<int, int> pr[1000005];   int high;   long long team[1000005], ir[1000005];   int main() {     scanf( %d %d , &n, &m);     int x, y;     for (int i = 0; i < m; i++) {       scanf( %d %d , &x, &y);       if (x < y) swap(x, y);       vr[x].push_back(y);     }     for (int i = 1; i < n + 1; i++) {       scanf( %d , &x);       for (int j = 0; j < x; j++) {         scanf( %d , &y);         tr[i].push_back(y);         high = max(high, y);       }     }     while (1) {       int tot = 0;       for (int i = 1; i < high + 1; i++) team[i] = rng() % 2 + 1;       for (int i = 1; i < n + 1; i++) {         ir[i] = tr[i][rng() % tr[i].size()];         for (int j = 0; j < vr[i].size(); j++) {           if (team[ir[vr[i][j]]] != team[ir[i]]) tot++;         }       }       if (tot >= m / 2 + (m % 2)) break;     }     for (int i = 1; i < n + 1; i++) printf( %d  , ir[i]);     printf(  n );     for (int i = 1; i < high + 1; i++) printf( %d  , team[i]);   }   