/*
 * This code is from "Algorithms in C, Third Edition,"
 * by Robert Sedgewick, Addison Wesley Longman, 1998.
 * (possibly with some small changes---check the book!)
 */
#include <stdio.h>
#include <stdlib.h>

#define VMAX 100

typedef struct node *link;
struct node { int v; link next; };

link NEW(int v, link next)
  { link x = malloc(sizeof *x);
    x->v = v; x->next = next;     
    return x;                         
  }

int main(int argc, char *argv[])
{ int i, j, V = atoi(argv[1]), M = 0;
  link adj[VMAX];
  for (i = 0; i < V; i++) adj[i] = NULL;
  while (scanf("%d %d\n", &i, &j) == 2) {
    adj[j] = NEW(i, adj[j]);
    adj[i] = NEW(j, adj[i]);
    M++;
  }
  for (i = 0; i < V; i++) {
    link t;
    printf("%2d: ", i);
    for (t = adj[i]; t; t = t->next)
      printf("%2d ", t->v);
    printf("\n");
  }
  printf("%d vertices and %d edges\n", V, M);  
  return 0;
}
