/* This program uses code from "Algorithms in C, Third Edition,"
 *               by Robert Sedgewick, Addison-Wesley, 1998.
 */

#include <stdio.h>

/* Made N smaller, so we can print all ids */
#define N 10

main()
{ 
  int i, p, q, t, id[N];
  for (i = 0; i < N; i++) id[i] = i;
  while (scanf("%d %d", &p, &q) == 2)
  { 
    if (id[p] == id[q]) 
    {
      printf(" %d and %d were on the same set\n", p, q);
      continue;
    }
    
    t = id[p];
    for (i = 0; i < N; i++)
      if (id[i] == t) id[i] = id[q];
    printf(" %d %d link led to set union\n", p, q);
    
    /* print updated ids after union */
    for (i = 0; i < N; i++)
    {
      printf("    id[%d] = %d\n", i, id[i]);
    }
  }
}
