import java.io.PrintStream;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Scanner;

/**
 * Solution to Investigating Imposters
 * 
 * @author vanb
 */
public class imposters_vanb
{
    /** Input. */
    private static Scanner sc;
    
    /** Output. */
    private static PrintStream ps;

    /** vouch[i][j] is true if villager i vouches for villager j. */
    private boolean vouch[][];
    
    /** Visited for a DFS. */
    private boolean visited[];
    
    /**
     * DFS counting depth.
     * 
     * @param villager
     * @return depth
     */
    private int depth( int villager )
    {
        int result = 1;

        visited[villager] = true;
        for( int i=0; i<vouch.length; i++ ) if( vouch[i][villager] && !visited[i] ) result += depth(i);

        return result;
    }

    /**
     * Do it!
     */
    private void doit()
    {
        int n = sc.nextInt();
        int k = sc.nextInt();
        
        vouch = new boolean[n][n];
        visited = new boolean[n];
        
        for( int i=0; i<n; i++ )
        {
            Arrays.fill( vouch[i], false );
            int s = sc.nextInt();
            
            for( int j=0; j<s; j++ ) vouch[i][sc.nextInt()-1] = true;
        }
        
        int chain[] = new int[n];
        for( int i=0; i<n; i++ )
        {
            Arrays.fill( visited,  false );
            chain[i] = 0;
            for( int j=0; j<n; j++ ) if( vouch[j][i] && !visited[j] ) chain[i] += depth(j);
        }
                
        
        int result[] = new int[n];
        Arrays.fill( result, 0 );
        
        for( int i=0; i<n; i++ ) if( chain[i]>k - (vouch[i][i]?0:1) ) result[i] = 1;
        
        boolean changed = true;
        while( changed )
        {
            changed = false;
            for( int i=0; i<n; i++ ) if( result[i]==1 )
            {
                for( int j=0; j<n; j++ ) if( vouch[i][j] && result[j]==0 )
                {
                    result[j] = 1;
                    changed = true;
                }
            }
        }
        
        for( int i : result ) ps.println( i );
    }
        
    /**
     * Main.
     * 
     * @param args unused
     * @throws Exception
     */
    public static void main( String[] args ) throws Exception
    {
        sc = new Scanner( System.in );
        ps = System.out;
        
        new imposters_vanb().doit();
        //System.exit( 0 );
    }

}
