#define MAIN 0
#include "bit.h"

// Code written by Wendy Myrvold.
// You can re-use this code in your projects.

// Reads a graph in adjacency list format and
// stores it in a compressed adjacency matrix.

// You probably want to add some error handling
// to this code.
int read_graph(int *n, int *m, int G[NMAX][MMAX])
{
    int i, j, u, d;

    if (scanf("%d", n)!= 1) return(0);

    *m= (*n+31)/32;

//  Initialize the graph to have no edges.

    for (i=0; i < *n; i++)
    {
        for (j=0; j < *m; j++)
        {
            G[i][j]= 0;
        }
    }

//  Read in the graph.

    for (i=0; i < *n; i++)
    {
        if (scanf("%d", &d)!=1) return(0);
        for (j=0; j < d; j++)
        {
            if (scanf("%d", &u)!=1) return(0);
            ADD_ELEMENT(G[i], u);
            ADD_ELEMENT(G[u], i);
        }
    }
    return(1);
}
// Compute the size of a set.
int set_size(int n, int set[])
{
    int j, m, d;

    m= (n+31)/ 32;

    d=0;

    for (j=0; j < m; j++)
    {
       d+= POP_COUNT(set[j]);
    }
    return(d);
}
// Prints a graph stored in the compressed adjacency format.
void print_graph(int n, int G[NMAX][MMAX])
{
    int i, j, d, m;


    for (i=0; i < n; i++)
    {
        d= set_size(n, G[i]);
        printf("%3d(%1d):", i, d);
        print_set(n, G[i]);
    }
}
// Prints a set.
void print_set(int n, int set[])
{
   int i;

   for (i=0; i < n; i++)
       if (IS_ELEMENT(set, i))
           printf("%3d", i);
   printf("\n");
}
