#include <iostream.h>
#define NODES 8

// prints all the trees on K_NODES.
// uses a Prufer decoding.
// see: http://www.math.niu.edu/~rusin/known-math/98/prufer

int code[NODES-2];

void decodeandprint () {
  bool marked[NODES];
  for (int i=0;i<NODES;i++) {
    marked[i] = false;
  } 
  for (int i=0;i<NODES-2;i++) {
    cout << code[i]+1;
    int sol;
    for (int j=0;j<NODES;j++) {
      if (marked[j]) continue;
      // is j in the code?
      bool incode = false;
      for (int k=i;k<NODES-2;k++) if (code[k] == j) {
        incode = true;
        break;
      }
      if (!incode) {
        sol = j;
        break;
      }
    }
    marked[sol] = true;
    cout << sol+1;
    cout << ";";
  }
  for (int j=0;j<NODES;j++) {
    if (!marked[j]) cout << j+1;
  }
  cout << ";\n";
}

void recurse (int codes) {
  if (codes == (NODES-2)) {
    decodeandprint();
  } else for (int i=0;i<NODES;i++) {
    code[codes] = i;
    recurse(codes+1);
  }
}

int main () {
  recurse(0);
  return(0);
}
