Example #1
0
 public void solve(int testNumber, InputReader in, OutputWriter out) {
   count = in.readInt();
   from = new int[count];
   to = new int[count];
   IOUtils.readIntArrays(in, from, to);
   previousSame = new int[count];
   for (int i = 0; i < count; i++) {
     for (int j = 0; j < i; j++) {
       if (from[i] == from[j] && to[i] == to[j] || from[i] == to[j] && to[i] == from[j])
         previousSame[i] += 1 << j;
     }
   }
   result = new long[8][8][1 << count];
   ArrayUtils.fill(result, -1);
   long answer = 0;
   for (int i = 0; i < count; i++) {
     if (previousSame[i] == 0) {
       answer += go(from[i], to[i], (1 << count) - 1 - (1 << i));
       if (from[i] != to[i]) answer += go(to[i], from[i], (1 << count) - 1 - (1 << i));
     }
   }
   out.printLine(answer);
 }