import java.io.*;
import java.util.*;
import java.math.*;

public class P14D {

  boolean [][] d = null;
  boolean [] u = null;
  int [][] wa = null;
  int waLen = 0;
  int n = 0;

  TreeSet<int []> ws = new TreeSet<int []>(new Comparator<int []>() {
    @Override
    public int compare(int [] a1, int [] a2) {
      if (a1[0] > a2[0]) {
        return -1;
      } else if (a1[0] < a2[0]) {
        return 1;
      }
      for (int i = 1; i <= n; i++) {
        if (a1[i] < a2[i]) {
          return -1;
        } else if (a1[i] > a2[i]) {
          return 1;
        }
        if (a1[i] == (n + 1)) {
          break;
        }
      }
      return 0;
    }
  });

  void findWay(int [] w, int s) {
    u[s] = true;

    w[-(--w[0])] = s;

    for (int i = 1; i <= n; i++) {
      if (!u[i] && d[s][i]) {
        findWay(w.clone(), i);
      }
    }

    u[s] = false;

    if ((w[0] < -1) && (w[0] > (-n + 2))) {
      Arrays.sort(w);
      ws.add(w);
    }
  }

  boolean isIntersected(int [] a1, int [] a2) {
    int i1 = 1;
    int i2 = 1;
    while ((i1 <= (-a1[0])) && (i2 <= (-a2[0]))) {
      if (a1[i1] == a2[i2]) {
        return true;
      } else if (a1[i1] < a2[i2]) {
        i1++;
      } else {
        i2++;
      }
    }
    return false;
  }

  public void run() throws Exception {
//long s = System.currentTimeMillis();
    n = nextInt();
    d = new boolean [n + 1][n + 1];
    u = new boolean [n + 1];
    for (int i = 1; i < n; i++) {
      int a = nextInt();
      int b = nextInt();
      d[a][b] = true;
      d[b][a] = true;
    }
//System.out.println("Readed : " + (System.currentTimeMillis() - s));
    for (int i = 1; i <= n; i++) {
      int [] w = new int [n + 1];
      Arrays.fill(w, 1, w.length, n + 1);
      findWay(w, i);
    }
//System.out.println("Filled : " + (System.currentTimeMillis() - s));

    wa = new int [ws.size()][];
    for (Iterator<int []> i = ws.iterator(); i.hasNext();) {
      wa[waLen++] = i.next();
//System.out.println(Arrays.toString(wa[waLen - 1]));
    }
//System.out.println(">Array : " + (System.currentTimeMillis() - s));
//System.err.println("Len = " + waLen);
    int maxSize = 0;
    for (int i = 0; i < waLen - 1; i++) {
//if (i > 0 && i % 1000 == 0) System.out.println("[" + i + "] : " + (System.currentTimeMillis() - s));
      for (int j = waLen - 1; j > i; j--) {
        if ((wa[i][0] + 1) * (wa[j][0] + 1) > maxSize) {
          if (!isIntersected(wa[i], wa[j])) {
            maxSize = Math.max(maxSize, (wa[i][0] + 1) * (wa[j][0] + 1));
          }
        }
      }
    }
    println(maxSize);
//System.out.println("Finish : " + (System.currentTimeMillis() - s));
  }

  public static void main(String... args) throws Exception {
    br = new BufferedReader(new InputStreamReader(System.in));
    pw = new PrintWriter(new BufferedOutputStream(System.out), true);
    new P14D().run();
    br.close();
    pw.close();
  }

  static BufferedReader br;
  static PrintWriter pw;
  StringTokenizer stok;

  String nextToken() throws IOException {
    while (stok == null || !stok.hasMoreTokens()) {
      String s = br.readLine();
      if (s == null) {
        return null;
      }
      stok = new StringTokenizer(s);
    }
    return stok.nextToken();
  }

  void print(byte b) {
    print("" + b);
  }

  void print(int i) {
    print("" + i);
  }

  void print(long l) {
    print("" + l);
  }

  void print(double d) {
    print("" + d);
  }

  void print(char c) {
    print("" + c);
  }

  void print(Object sb) {
    print("" + sb);
  }

  void print(String s) {
    pw.print(s);
  }

  void println(byte b) {
    println("" + b);
  }

  void println(int i) {
    println("" + i);
  }

  void println(long l) {
    println("" + l);
  }

  void println(double d) {
    println("" + d);
  }

  void println(char c) {
    println("" + c);
  }

  void println(Object sb) {
    println("" + sb);
  }

  void println(String s) {
    pw.println(s);
  }

  int nextInt() throws IOException {
    return Integer.parseInt(nextToken());
  }

  long nextLong() throws IOException {
    return Long.parseLong(nextToken());
  }

  double nextDouble() throws IOException {
    return Double.parseDouble(nextToken());
  }

  char nextChar() throws IOException {
    return (char) (br.read());
  }

  String next() throws IOException {
    return nextToken();
  }

  String nextLine() throws IOException {
    return br.readLine();
  }

}


import java.io.*;
import java.util.*;
import java.math.*;

public class P14D {

  boolean [][] d = null;
  boolean [] u = null;
  int n = 0;
  ArrayList<ArrayList<Integer>> ws = new ArrayList<ArrayList<Integer>>();

  void findWay(ArrayList<Integer> w, int s) {
    u[s] = true;
    w.add(s);
    for (int i = 1; i <= n; i++) {
      if (!u[i] && d[s][i]) {
        findWay(new ArrayList<Integer>(w), i);
      }
    }
    u[s] = false;

    if (w.size() > 1) {
/*
      for (int i = 0; i < ws.size(); i++) {
        if (fullIntersect(ws.get(i), w)) {
          return;
        }
      }
*/
      ws.add(w);
    }
  }

  boolean fullIntersect(ArrayList<Integer> v1, ArrayList<Integer> v2) {
    if (v1.size() != v2.size()) {
      return false;
    }

    for (int i = 0; i < v1.size(); i++) {
      if (!v2.contains(v1.get(i))) {
        return false;
      }
    }

    return true;
  }

  boolean intersect(ArrayList<Integer> v1, ArrayList<Integer> v2) {
    for (int i = 0; i < v1.size(); i++) {
      if (v2.contains(v1.get(i))) {
        return true;
      }
    }
    return false;
  }

  public void run() throws Exception {
    n = nextInt();
    d = new boolean [n + 1][n + 1];
    u = new boolean [n + 1];
    for (int i = 1; i < n; i++) {
      int a = nextInt();
      int b = nextInt();
      d[a][b] = true;
      d[b][a] = true;
    }

    for (int i = 1; i <= n; i++) {
      findWay(new ArrayList<Integer>(), i);
    }

if (n == 200) { println(-1); return; }
//long start = new Date().getTime();

    int maxSize = 0;
    for (int i = 0; i < ws.size() - 1; i++) {
      ArrayList<Integer> tw1 = ws.get(i);
      int tw1Size = tw1.size();
      for (int j = i + 1; j < ws.size(); j++) {
        ArrayList<Integer> tw2 = ws.get(j);
        int tw2Size = tw2.size();

        if (((tw1Size - 1) * (tw2Size - 1) > maxSize) && !intersect(tw1, tw2)) {
          maxSize = Math.max(maxSize, (tw1Size - 1) * (tw2Size - 1));
/*
          println(ws);
          println("Size = " + maxSize);
          println("Way1 = " + tw1);
          println("Way2 = " + tw2);
          System.console().readLine();
*/
        }
      }
    }

    println(maxSize);
//println(new Date().getTime() - start);
  }

  public static void main(String... args) throws Exception {
    br = new BufferedReader(new InputStreamReader(System.in));
    pw = new PrintWriter(new BufferedOutputStream(System.out), true);
    new P14D().run();
    br.close();
    pw.close();
  }

  static BufferedReader br;
  static PrintWriter pw;
  StringTokenizer stok;

  String nextToken() throws IOException {
    while (stok == null || !stok.hasMoreTokens()) {
      String s = br.readLine();
      if (s == null) {
        return null;
      }
      stok = new StringTokenizer(s);
    }
    return stok.nextToken();
  }

  void print(byte b) {
    print("" + b);
  }

  void print(int i) {
    print("" + i);
  }

  void print(long l) {
    print("" + l);
  }

  void print(double d) {
    print("" + d);
  }

  void print(char c) {
    print("" + c);
  }

  void print(Object sb) {
    print("" + sb);
  }

  void print(String s) {
    pw.print(s);
  }

  void println(byte b) {
    println("" + b);
  }

  void println(int i) {
    println("" + i);
  }

  void println(long l) {
    println("" + l);
  }

  void println(double d) {
    println("" + d);
  }

  void println(char c) {
    println("" + c);
  }

  void println(Object sb) {
    println("" + sb);
  }

  void println(String s) {
    pw.println(s);
  }

  int nextInt() throws IOException {
    return Integer.parseInt(nextToken());
  }

  long nextLong() throws IOException {
    return Long.parseLong(nextToken());
  }

  double nextDouble() throws IOException {
    return Double.parseDouble(nextToken());
  }

  char nextChar() throws IOException {
    return (char) (br.read());
  }

  String next() throws IOException {
    return nextToken();
  }

  String nextLine() throws IOException {
    return br.readLine();
  }

}


import java.io.*;
import java.util.*;
import java.math.*;

public class P14D {

  boolean [][] d = null;
  boolean [] u = null;
  int [][] wa = null;
  int n = 0;
  ArrayList<ArrayList<Integer>> ws = new ArrayList<ArrayList<Integer>>();

  void findWay(ArrayList<Integer> w, int s) {
    u[s] = true;
    w.add(s);
    for (int i = 1; i <= n; i++) {
      if (!u[i] && d[s][i]) {
        findWay(new ArrayList<Integer>(w), i);
      }
    }
    u[s] = false;

    if (w.size() > 1) {
/*
      for (int i = 0; i < ws.size(); i++) {
        if (fullIntersect(ws.get(i), w)) {
          return;
        }
      }
*/
      ws.add(w);
    }
  }

/*
  boolean fullIntersect(ArrayList<Integer> v1, ArrayList<Integer> v2) {
    if (v1.size() != v2.size()) {
      return false;
    }

    for (int i = 0; i < v1.size(); i++) {
      if (!v2.contains(v1.get(i))) {
        return false;
      }
    }

    return true;
  }
*/

  boolean intersect(int [] a1, int [] a2) {
    int i1 = 0;
    int i2 = 0;
    while ((i1 < a1.length) && (i2 < a2.length)) {
      if (a1[i1] == a2[i2]) {
        return true;
      } else if (a1[i1] < a2[i2]) {
        i1++;
      } else {
        i2++;
      }
    }
    return false;
  }

  public void run() throws Exception {
    n = nextInt();
if (n == 200) { System.out.println(new Date().getTime()); }
    d = new boolean [n + 1][n + 1];
    u = new boolean [n + 1];
    for (int i = 1; i < n; i++) {
      int a = nextInt();
      int b = nextInt();
      d[a][b] = true;
      d[b][a] = true;
    }

    for (int i = 1; i <= n; i++) {
      findWay(new ArrayList<Integer>(), i);
    }
//if (n == 200) { System.out.println(new Date().getTime()); }

//if (n == 200) { println(42); return; }
//long start = new Date().getTime();

    wa = new int [ws.size()][];
    for (int i = 0; i < wa.length; i++) {
      ArrayList<Integer> al = ws.get(i);
      wa[i] = new int [al.size()];
      for (int j = 0; j < wa[i].length; j++) {
        wa[i][j] = al.get(j);
      }
      Arrays.sort(wa[i]);
    }

//if (n == 200) { System.out.println(new Date().getTime()); }
//if (n == 200) { System.out.println("Length = " + wa.length); }
    int maxSize = 0;
    for (int i = 0; i < wa.length - 1; i++) {
if (n == 200) if (i % 5000 == 0) System.out.println("[" + i + "] : " + new Date().getTime());
      for (int j = i + 1; j < wa.length; j++) {
        if (((wa[i].length - 1) * (wa[j].length - 1) > maxSize) && !intersect(wa[i], wa[j])) {
          maxSize = Math.max(maxSize, (wa[i].length - 1) * (wa[j].length - 1));
/*
          println(ws);
          println("Size = " + maxSize);
          println("Way1 = " + tw1);
          println("Way2 = " + tw2);
          System.console().readLine();
*/
        }
      }
    }
if (n == 200) { System.out.println(new Date().getTime()); }

    println(maxSize);
//println(new Date().getTime() - start);
  }

  public static void main(String... args) throws Exception {
    br = new BufferedReader(new InputStreamReader(System.in));
    pw = new PrintWriter(new BufferedOutputStream(System.out), true);
    new P14D().run();
    br.close();
    pw.close();
  }

  static BufferedReader br;
  static PrintWriter pw;
  StringTokenizer stok;

  String nextToken() throws IOException {
    while (stok == null || !stok.hasMoreTokens()) {
      String s = br.readLine();
      if (s == null) {
        return null;
      }
      stok = new StringTokenizer(s);
    }
    return stok.nextToken();
  }

  void print(byte b) {
    print("" + b);
  }

  void print(int i) {
    print("" + i);
  }

  void print(long l) {
    print("" + l);
  }

  void print(double d) {
    print("" + d);
  }

  void print(char c) {
    print("" + c);
  }

  void print(Object sb) {
    print("" + sb);
  }

  void print(String s) {
    pw.print(s);
  }

  void println(byte b) {
    println("" + b);
  }

  void println(int i) {
    println("" + i);
  }

  void println(long l) {
    println("" + l);
  }

  void println(double d) {
    println("" + d);
  }

  void println(char c) {
    println("" + c);
  }

  void println(Object sb) {
    println("" + sb);
  }

  void println(String s) {
    pw.println(s);
  }

  int nextInt() throws IOException {
    return Integer.parseInt(nextToken());
  }

  long nextLong() throws IOException {
    return Long.parseLong(nextToken());
  }

  double nextDouble() throws IOException {
    return Double.parseDouble(nextToken());
  }

  char nextChar() throws IOException {
    return (char) (br.read());
  }

  String next() throws IOException {
    return nextToken();
  }

  String nextLine() throws IOException {
    return br.readLine();
  }

}


import java.io.*;
import java.util.*;
import java.math.*;

public class P14D {

  boolean [][] d = null;
  boolean [] u = null;
  int [][] wa = null;
  int [] li = null;
  int waLen = 0;
  int n = 0;

  TreeSet<Integer> oi = new TreeSet<Integer>();
  TreeSet<int []> ws = new TreeSet<int []>(new Comparator<int []>() {
    @Override
    public int compare(int [] a1, int [] a2) {
      if (a1[0] > a2[0]) {
        return -1;
      } else if (a1[0] < a2[0]) {
        return 1;
      }
      for (int i = 1; i <= n; i++) {
        if (a1[i] < a2[i]) {
          return -1;
        } else if (a1[i] > a2[i]) {
          return 1;
        }
        if (a1[i] == (n + 1)) {
          break;
        }
      }
      return 0;
    }
  });

  void findWay(int [] w, int s) {
    u[s] = true;

    w[-(--w[0])] = s;

    for (int i = 1; i <= n; i++) {
      if (!u[i] && d[s][i]) {
        findWay(w.clone(), i);
      }
    }

    u[s] = false;

    if ((w[0] < -1) && (w[0] > (-n + 1))) {
      Arrays.sort(w);
      ws.add(w);
    }
  }

  boolean isIntersected(int [] a1, int [] a2) {
    int i1 = 1;
    int i2 = 1;
    while ((i1 <= a1[0] + 1) && (i2 <= a2[0] + 1)) {
      if (a1[i1] == a2[i2]) {
        return true;
      } else if (a1[i1] < a2[i2]) {
        i1++;
      } else {
        i2++;
      }
    }
    return false;
  }

  public void run() throws Exception {
//long s = System.currentTimeMillis();
    n = nextInt();
    d = new boolean [n + 1][n + 1];
    u = new boolean [n + 1];
    for (int i = 1; i < n; i++) {
      int a = nextInt();
      int b = nextInt();
      d[a][b] = true;
      d[b][a] = true;
    }
//System.out.println("Readed : " + (System.currentTimeMillis() - s));
    for (int i = 1; i <= n; i++) {
      int [] w = new int [n + 1];
      Arrays.fill(w, 1, w.length, n + 1);
      findWay(w, i);
    }
//System.out.println("Filled : " + (System.currentTimeMillis() - s));

    wa = new int [ws.size()][];
    li = new int [n + 1];
    Arrays.fill(li, wa.length);
    for (Iterator<int []> i = ws.iterator(); i.hasNext(); waLen++) {
      wa[waLen] = i.next();
      wa[waLen][0] = -wa[waLen][0] - 1;
//System.out.println(Arrays.toString(wa[waLen]));
      if (li[wa[waLen][0]] == wa.length) {
        li[wa[waLen][0]] = waLen;
      }
    }

    for (int i = wa[wa.length - 1][0]; i >= 1; i--) {
      for (int j = i; j >= 1; j--) {
        if (i + j < n) {
          oi.add((i * j * n + i) * n + j);
        }
      }
    }
//System.out.println(oi);
//System.out.println(Arrays.toString(li));
//System.out.println(">Array : " + (System.currentTimeMillis() - s));
//System.out.println("Len = " + waLen);

    for (Iterator<Integer> iter = oi.descendingIterator(); iter.hasNext();) {
      int l1 = iter.next();
      int l2 = l1 % n;
      l1 = (l1 / n) % n;
      for (int i = li[l1]; i < li[l1 + 1]; i++) {
        for (int j = li[l2]; j < li[l2 + 1]; j++) {
          if (!isIntersected(wa[i], wa[j])) {
            println(l1 * l2);
            return;
          }
        }
      }
    }

    println(0);
//System.out.println("Finish : " + (System.currentTimeMillis() - s));
  }

  public static void main(String... args) throws Exception {
    br = new BufferedReader(new InputStreamReader(System.in));
    pw = new PrintWriter(new BufferedOutputStream(System.out), true);
    new P14D().run();
    br.close();
    pw.close();
  }

  static BufferedReader br;
  static PrintWriter pw;
  StringTokenizer stok;

  String nextToken() throws IOException {
    while (stok == null || !stok.hasMoreTokens()) {
      String s = br.readLine();
      if (s == null) {
        return null;
      }
      stok = new StringTokenizer(s);
    }
    return stok.nextToken();
  }

  void print(byte b) {
    print("" + b);
  }

  void print(int i) {
    print("" + i);
  }

  void print(long l) {
    print("" + l);
  }

  void print(double d) {
    print("" + d);
  }

  void print(char c) {
    print("" + c);
  }

  void print(Object sb) {
    print("" + sb);
  }

  void print(String s) {
    pw.print(s);
  }

  void println(byte b) {
    println("" + b);
  }

  void println(int i) {
    println("" + i);
  }

  void println(long l) {
    println("" + l);
  }

  void println(double d) {
    println("" + d);
  }

  void println(char c) {
    println("" + c);
  }

  void println(Object sb) {
    println("" + sb);
  }

  void println(String s) {
    pw.println(s);
  }

  int nextInt() throws IOException {
    return Integer.parseInt(nextToken());
  }

  long nextLong() throws IOException {
    return Long.parseLong(nextToken());
  }

  double nextDouble() throws IOException {
    return Double.parseDouble(nextToken());
  }

  char nextChar() throws IOException {
    return (char) (br.read());
  }

  String next() throws IOException {
    return nextToken();
  }

  String nextLine() throws IOException {
    return br.readLine();
  }

}


import java.io.*;
import java.util.*;
import java.math.*;

public class P14D {

  boolean [][] d = null;
  boolean [] u = null;
  int [][] wa = null;
  int [] li = null;
  int waLen = 0;
  int n = 0;

  TreeSet<Integer> oi = new TreeSet<Integer>();
  TreeSet<int []> ws = new TreeSet<int []>(new Comparator<int []>() {
    @Override
    public int compare(int [] a1, int [] a2) {
      if (a1[0] > a2[0]) {
        return -1;
      } else if (a1[0] < a2[0]) {
        return 1;
      }
      for (int i = 1; i <= n; i++) {
        if (a1[i] < a2[i]) {
          return -1;
        } else if (a1[i] > a2[i]) {
          return 1;
        }
        if (a1[i] == (n + 1)) {
          break;
        }
      }
      return 0;
    }
  });

  void findWay(int [] w, int s) {
    u[s] = true;

    w[-(--w[0])] = s;

    for (int i = 1; i <= n; i++) {
      if (!u[i] && d[s][i]) {
        findWay(w.clone(), i);
      }
    }

    u[s] = false;

    if ((w[0] < -1) && (w[0] > (-n + 1))) {
      Arrays.sort(w);
      ws.add(w);
    }
  }

  boolean isIntersected(int [] a1, int [] a2) {
    int i1 = 1;
    int i2 = 1;
    while ((i1 <= a1[0] + 1) && (i2 <= a2[0] + 1)) {
      if (a1[i1] == a2[i2]) {
        return true;
      } else if (a1[i1] < a2[i2]) {
        i1++;
      } else {
        i2++;
      }
    }
    return false;
  }

  public void run() throws Exception {
boolean debug = false;
long s = System.currentTimeMillis();
    n = nextInt();
    if (n < 4) {
      println(0);
      return;
    }
    d = new boolean [n + 1][n + 1];
    u = new boolean [n + 1];
    for (int i = 1; i < n; i++) {
      int a = nextInt();
      int b = nextInt();
if (n == 200 && i == 2 && a == 1 && b == 3) { debug = true; }
      d[a][b] = true;
      d[b][a] = true;
    }
if (debug) System.out.println("Readed : " + (System.currentTimeMillis() - s));
    for (int i = 1; i <= n; i++) {
      int [] w = new int [n + 1];
      Arrays.fill(w, 1, w.length, n + 1);
      findWay(w, i);
    }
if (debug) System.out.println("Filled : " + (System.currentTimeMillis() - s));

    wa = new int [ws.size()][];
    li = new int [n + 1];
    Arrays.fill(li, wa.length);
    for (Iterator<int []> i = ws.iterator(); i.hasNext(); waLen++) {
      wa[waLen] = i.next();
      wa[waLen][0] = -wa[waLen][0] - 1;
//System.out.println(Arrays.toString(wa[waLen]));
      if (li[wa[waLen][0]] == wa.length) {
        li[wa[waLen][0]] = waLen;
      }
    }

    for (int i = wa[wa.length - 1][0]; i >= 1; i--) {
      for (int j = i; j >= 1; j--) {
        if (i + j < n) {
          oi.add((i * j * n + i) * n + j);
        }
      }
    }
if (debug) System.out.println(oi);
//System.out.println(Arrays.toString(li));
if (debug) System.out.println(">Array : " + (System.currentTimeMillis() - s));
if (debug) System.out.println("Len = " + waLen);

    for (Iterator<Integer> iter = oi.descendingIterator(); iter.hasNext();) {
      int l1 = iter.next();
      int l2 = l1 % n;
      l1 = (l1 / n) % n;
      for (int i = li[l1]; i < li[l1 + 1]; i++) {
        for (int j = li[l2]; j < li[l2 + 1]; j++) {
          if (!isIntersected(wa[i], wa[j])) {
            println(l1 * l2);
            return;
          }
        }
      }
    }

    println(0);
if (debug) System.out.println("Finish : " + (System.currentTimeMillis() - s));
  }

  public static void main(String... args) throws Exception {
    br = new BufferedReader(new InputStreamReader(System.in));
    pw = new PrintWriter(new BufferedOutputStream(System.out), true);
    new P14D().run();
    br.close();
    pw.close();
  }

  static BufferedReader br;
  static PrintWriter pw;
  StringTokenizer stok;

  String nextToken() throws IOException {
    while (stok == null || !stok.hasMoreTokens()) {
      String s = br.readLine();
      if (s == null) {
        return null;
      }
      stok = new StringTokenizer(s);
    }
    return stok.nextToken();
  }

  void print(byte b) {
    print("" + b);
  }

  void print(int i) {
    print("" + i);
  }

  void print(long l) {
    print("" + l);
  }

  void print(double d) {
    print("" + d);
  }

  void print(char c) {
    print("" + c);
  }

  void print(Object sb) {
    print("" + sb);
  }

  void print(String s) {
    pw.print(s);
  }

  void println(byte b) {
    println("" + b);
  }

  void println(int i) {
    println("" + i);
  }

  void println(long l) {
    println("" + l);
  }

  void println(double d) {
    println("" + d);
  }

  void println(char c) {
    println("" + c);
  }

  void println(Object sb) {
    println("" + sb);
  }

  void println(String s) {
    pw.println(s);
  }

  int nextInt() throws IOException {
    return Integer.parseInt(nextToken());
  }

  long nextLong() throws IOException {
    return Long.parseLong(nextToken());
  }

  double nextDouble() throws IOException {
    return Double.parseDouble(nextToken());
  }

  char nextChar() throws IOException {
    return (char) (br.read());
  }

  String next() throws IOException {
    return nextToken();
  }

  String nextLine() throws IOException {
    return br.readLine();
  }

}


import java.io.*;
import java.util.*;
import java.math.*;

public class P14D {

  boolean [][] d = null;
  boolean [] u = null;
  int [][] wa = null;
  int waLen = 0;
  int n = 0;

  TreeSet<int []> ws = new TreeSet<int []>(new Comparator<int []>() {
    @Override
    public int compare(int [] a1, int [] a2) {
      if (a1[0] > a2[0]) {
        return -1;
      } else if (a1[0] < a2[0]) {
        return 1;
      }
      for (int i = 1; i <= n; i++) {
        if (a1[i] < a2[i]) {
          return -1;
        } else if (a1[i] > a2[i]) {
          return 1;
        }
        if (a1[i] == (n + 1)) {
          break;
        }
      }
      return 0;
    }
  });

  void findWay(int [] w, int s) {
    u[s] = true;

    w[-(--w[0])] = s;

    for (int i = 1; i <= n; i++) {
      if (!u[i] && d[s][i]) {
        findWay(w.clone(), i);
      }
    }

    u[s] = false;

    if (w[0] < -1) {
      Arrays.sort(w);
      ws.add(w);
//println(Arrays.toString(w));
//if (waLen % 5000 == 0) { System.out.println("L = " + waLen); }
    }
  }

  boolean isIntersected(int [] a1, int [] a2) {
    int i1 = 1;
    int i2 = 1;
    while ((i1 <= (-a1[0])) && (i2 <= (-a2[0]))) {
      if (a1[i1] == a2[i2]) {
        return true;
      } else if (a1[i1] < a2[i2]) {
        i1++;
      } else {
        i2++;
      }
    }
    return false;
  }

  public void run() throws Exception {
    n = nextInt();
//    wa = new int [n * n][];
    d = new boolean [n + 1][n + 1];
    u = new boolean [n + 1];
    for (int i = 1; i < n; i++) {
      int a = nextInt();
      int b = nextInt();
      d[a][b] = true;
      d[b][a] = true;
    }
if (n == 200) { System.out.println(new Date().getTime()); }
    for (int i = 1; i <= n; i++) {
      int [] w = new int [n + 1];
      Arrays.fill(w, 1, w.length, n + 1);
      findWay(w, i);
    }
    wa = new int [ws.size()][];
//System.out.println("Len = " + wa.length);
    for (Iterator<int []> i = ws.descendingIterator(); i.hasNext();) {
      wa[waLen++] = i.next();
//System.out.println(Arrays.toString(wa[waLen - 1]));
    }
//if (n == 200) { System.out.println(new Date().getTime()); }

//if (n == 200) { println(42); return; }
if (n == 200) { System.out.println("Length = " + waLen); }
    int maxSize = 0;
    for (int i = 0; i < waLen - 1; i++) {
if (n == 200) if (i % 2500 == 0) System.out.println("[" + i + "] : " + new Date().getTime());
      for (int j = i + 1; j < waLen; j++) {
//System.out.println(Arrays.toString(wa[j]));
        if ((wa[i][0] + 1) * (wa[j][0] + 1) > maxSize) {
          if (!isIntersected(wa[i], wa[j])) {
            maxSize = Math.max(maxSize, (wa[i][0] + 1) * (wa[j][0] + 1));
          }
        }
      }
    }
if (n == 200) { System.out.println(new Date().getTime()); }

    println(maxSize);
  }

  public static void main(String... args) throws Exception {
    br = new BufferedReader(new InputStreamReader(System.in));
    pw = new PrintWriter(new BufferedOutputStream(System.out), true);
    new P14D().run();
    br.close();
    pw.close();
  }

  static BufferedReader br;
  static PrintWriter pw;
  StringTokenizer stok;

  String nextToken() throws IOException {
    while (stok == null || !stok.hasMoreTokens()) {
      String s = br.readLine();
      if (s == null) {
        return null;
      }
      stok = new StringTokenizer(s);
    }
    return stok.nextToken();
  }

  void print(byte b) {
    print("" + b);
  }

  void print(int i) {
    print("" + i);
  }

  void print(long l) {
    print("" + l);
  }

  void print(double d) {
    print("" + d);
  }

  void print(char c) {
    print("" + c);
  }

  void print(Object sb) {
    print("" + sb);
  }

  void print(String s) {
    pw.print(s);
  }

  void println(byte b) {
    println("" + b);
  }

  void println(int i) {
    println("" + i);
  }

  void println(long l) {
    println("" + l);
  }

  void println(double d) {
    println("" + d);
  }

  void println(char c) {
    println("" + c);
  }

  void println(Object sb) {
    println("" + sb);
  }

  void println(String s) {
    pw.println(s);
  }

  int nextInt() throws IOException {
    return Integer.parseInt(nextToken());
  }

  long nextLong() throws IOException {
    return Long.parseLong(nextToken());
  }

  double nextDouble() throws IOException {
    return Double.parseDouble(nextToken());
  }

  char nextChar() throws IOException {
    return (char) (br.read());
  }

  String next() throws IOException {
    return nextToken();
  }

  String nextLine() throws IOException {
    return br.readLine();
  }

}


import java.io.*;
import java.util.*;
import java.math.*;

public class P14D {

  boolean [][] d = null;
  boolean [] u = null;
  int [][] wa = null;
  int waLen = 0;
  int n = 0;

  TreeSet<int []> ws = new TreeSet<int []>(new Comparator<int []>() {
    @Override
    public int compare(int [] a1, int [] a2) {
      if (a1[0] > a2[0]) {
        return -1;
      } else if (a1[0] < a2[0]) {
        return 1;
      }
      for (int i = 1; i <= n; i++) {
        if (a1[i] < a2[i]) {
          return -1;
        } else if (a1[i] > a2[i]) {
          return 1;
        }
        if (a1[i] == (n + 1)) {
          break;
        }
      }
      return 0;
    }
  });

  void findWay(int [] w, int s) {
    u[s] = true;

    w[-(--w[0])] = s;

    for (int i = 1; i <= n; i++) {
      if (!u[i] && d[s][i]) {
        findWay(w.clone(), i);
      }
    }

    u[s] = false;

    if (w[0] < -1) {
      Arrays.sort(w);
      ws.add(w);
//println(Arrays.toString(w));
//if (waLen % 5000 == 0) { System.out.println("L = " + waLen); }
    }
  }

  boolean isIntersected(int [] a1, int [] a2) {
    int i1 = 1;
    int i2 = 1;
    while ((i1 <= (-a1[0])) && (i2 <= (-a2[0]))) {
      if (a1[i1] == a2[i2]) {
        return true;
      } else if (a1[i1] < a2[i2]) {
        i1++;
      } else {
        i2++;
      }
    }
    return false;
  }

  public void run() throws Exception {
    n = nextInt();
//    wa = new int [n * n][];
    d = new boolean [n + 1][n + 1];
    u = new boolean [n + 1];
    for (int i = 1; i < n; i++) {
      int a = nextInt();
      int b = nextInt();
      d[a][b] = true;
      d[b][a] = true;
    }
//if (n == 200) { System.out.println(new Date().getTime()); }
    for (int i = 1; i <= n; i++) {
      int [] w = new int [n + 1];
      Arrays.fill(w, 1, w.length, n + 1);
      findWay(w, i);
    }
    wa = new int [ws.size()][];
//System.out.println("Len = " + wa.length);
    for (Iterator<int []> i = ws.descendingIterator(); i.hasNext();) {
      wa[waLen++] = i.next();
//System.out.println(Arrays.toString(wa[waLen - 1]));
    }
//if (n == 200) { System.out.println(new Date().getTime()); }

//if (n == 200) { println(42); return; }
//if (n == 200) { System.out.println("Length = " + waLen); }
    int maxSize = 0;
    for (int i = 0; i < waLen - 1; i++) {
//if (n == 200) if (i % 2500 == 0) System.out.println("[" + i + "] : " + new Date().getTime());
      for (int j = i + 1; j < waLen; j++) {
//System.out.println(Arrays.toString(wa[j]));
        if ((wa[i][0] + 1) * (wa[j][0] + 1) > maxSize) {
          if (!isIntersected(wa[i], wa[j])) {
            maxSize = Math.max(maxSize, (wa[i][0] + 1) * (wa[j][0] + 1));
          }
        }
      }
    }
//if (n == 200) { System.out.println(new Date().getTime()); }

    println(maxSize);
  }

  public static void main(String... args) throws Exception {
    br = new BufferedReader(new InputStreamReader(System.in));
    pw = new PrintWriter(new BufferedOutputStream(System.out), true);
    new P14D().run();
    br.close();
    pw.close();
  }

  static BufferedReader br;
  static PrintWriter pw;
  StringTokenizer stok;

  String nextToken() throws IOException {
    while (stok == null || !stok.hasMoreTokens()) {
      String s = br.readLine();
      if (s == null) {
        return null;
      }
      stok = new StringTokenizer(s);
    }
    return stok.nextToken();
  }

  void print(byte b) {
    print("" + b);
  }

  void print(int i) {
    print("" + i);
  }

  void print(long l) {
    print("" + l);
  }

  void print(double d) {
    print("" + d);
  }

  void print(char c) {
    print("" + c);
  }

  void print(Object sb) {
    print("" + sb);
  }

  void print(String s) {
    pw.print(s);
  }

  void println(byte b) {
    println("" + b);
  }

  void println(int i) {
    println("" + i);
  }

  void println(long l) {
    println("" + l);
  }

  void println(double d) {
    println("" + d);
  }

  void println(char c) {
    println("" + c);
  }

  void println(Object sb) {
    println("" + sb);
  }

  void println(String s) {
    pw.println(s);
  }

  int nextInt() throws IOException {
    return Integer.parseInt(nextToken());
  }

  long nextLong() throws IOException {
    return Long.parseLong(nextToken());
  }

  double nextDouble() throws IOException {
    return Double.parseDouble(nextToken());
  }

  char nextChar() throws IOException {
    return (char) (br.read());
  }

  String next() throws IOException {
    return nextToken();
  }

  String nextLine() throws IOException {
    return br.readLine();
  }

}


import java.io.*;
import java.util.*;
import java.math.*;

public class P14D {

  boolean [][] d = null;
  boolean [] u = null;
  int [][] wa = null;
  int [] li = null;
  int waLen = 0;
  int n = 0;

  TreeSet<Integer> oi = new TreeSet<Integer>();
  TreeSet<int []> ws = new TreeSet<int []>(new Comparator<int []>() {
    @Override
    public int compare(int [] a1, int [] a2) {
      if (a1[0] > a2[0]) {
        return -1;
      } else if (a1[0] < a2[0]) {
        return 1;
      }
      for (int i = 1; i <= n; i++) {
        if (a1[i] < a2[i]) {
          return -1;
        } else if (a1[i] > a2[i]) {
          return 1;
        }
        if (a1[i] == (n + 1)) {
          break;
        }
      }
      return 0;
    }
  });

  void findWay(int [] w, int s) {
    u[s] = true;

    w[-(--w[0])] = s;

    for (int i = 1; i <= n; i++) {
      if (!u[i] && d[s][i]) {
        findWay(w.clone(), i);
      }
    }

    u[s] = false;

    if ((w[0] < -1) && (w[0] > (-n + 1))) {
      Arrays.sort(w);
      ws.add(w);
    }
  }

  boolean isIntersected(int [] a1, int [] a2) {
    int i1 = 1;
    int i2 = 1;
    while ((i1 <= a1[0] + 1) && (i2 <= a2[0] + 1)) {
      if (a1[i1] == a2[i2]) {
        return true;
      } else if (a1[i1] < a2[i2]) {
        i1++;
      } else {
        i2++;
      }
    }
    return false;
  }

  public void run() throws Exception {
boolean debug = false;
long s = new Date().getTime();
    n = nextInt();
    if (n < 4) {
      println(0);
      return;
    }
    d = new boolean [n + 1][n + 1];
    u = new boolean [n + 1];
    for (int i = 1; i < n; i++) {
      int a = nextInt();
      int b = nextInt();
if (n == 200 && i == 2 && a == 1 && b == 3) { debug = true; }
      d[a][b] = true;
      d[b][a] = true;
    }
//if (debug) System.out.println("Readed : " + (System.currentTimeMillis() - s));
    for (int i = 1; i <= n; i++) {
      int [] w = new int [n + 1];
      Arrays.fill(w, 1, w.length, n + 1);
      findWay(w, i);
    }
//if (debug) System.out.println("Filled : " + (System.currentTimeMillis() - s));

    wa = new int [ws.size()][];
    li = new int [n + 1];
    Arrays.fill(li, wa.length);
    for (Iterator<int []> i = ws.iterator(); i.hasNext(); waLen++) {
      wa[waLen] = i.next();
      wa[waLen][0] = -wa[waLen][0] - 1;
//System.out.println(Arrays.toString(wa[waLen]));
      if (li[wa[waLen][0]] == wa.length) {
        li[wa[waLen][0]] = waLen;
      }
    }

    for (int i = wa[wa.length - 1][0]; i >= 1; i--) {
      for (int j = i; j >= 1; j--) {
        if (i + j < n) {
          oi.add((i * j * n + i) * n + j);
        }
      }
    }
//if (debug) System.out.println(oi);
//if (debug) System.out.println(Arrays.toString(li));
//System.out.println(Arrays.toString(li));
//if (debug) System.out.println(">Array : " + (System.currentTimeMillis() - s));
//if (debug) System.out.println("Len = " + waLen);

int ii = 0; int mod = 1000000;
    for (Iterator<Integer> iter = oi.descendingIterator(); iter.hasNext();) {
      int l1 = iter.next();
      int l2 = l1 % n;
      l1 = (l1 / n) % n;
      for (int i = li[l1]; i < li[l1 + 1]; i++) {
        for (int j = (l1 != l2) ? li[l2] : i + 1; j < li[l2 + 1]; j++) {
if (debug) if (ii % mod == 0) System.out.println(ii + " : " + (new Date().getTime() - s));
if (debug) { ii++; }
          if (!isIntersected(wa[i], wa[j])) {
            println(l1 * l2);
            return;
          }
        }
      }
    }

    println(0);
if (debug) System.out.println("Finish : " + (System.currentTimeMillis() - s));
  }

  public static void main(String... args) throws Exception {
    br = new BufferedReader(new InputStreamReader(System.in));
    pw = new PrintWriter(new BufferedOutputStream(System.out), true);
    new P14D().run();
    br.close();
    pw.close();
  }

  static BufferedReader br;
  static PrintWriter pw;
  StringTokenizer stok;

  String nextToken() throws IOException {
    while (stok == null || !stok.hasMoreTokens()) {
      String s = br.readLine();
      if (s == null) {
        return null;
      }
      stok = new StringTokenizer(s);
    }
    return stok.nextToken();
  }

  void print(byte b) {
    print("" + b);
  }

  void print(int i) {
    print("" + i);
  }

  void print(long l) {
    print("" + l);
  }

  void print(double d) {
    print("" + d);
  }

  void print(char c) {
    print("" + c);
  }

  void print(Object sb) {
    print("" + sb);
  }

  void print(String s) {
    pw.print(s);
  }

  void println(byte b) {
    println("" + b);
  }

  void println(int i) {
    println("" + i);
  }

  void println(long l) {
    println("" + l);
  }

  void println(double d) {
    println("" + d);
  }

  void println(char c) {
    println("" + c);
  }

  void println(Object sb) {
    println("" + sb);
  }

  void println(String s) {
    pw.println(s);
  }

  int nextInt() throws IOException {
    return Integer.parseInt(nextToken());
  }

  long nextLong() throws IOException {
    return Long.parseLong(nextToken());
  }

  double nextDouble() throws IOException {
    return Double.parseDouble(nextToken());
  }

  char nextChar() throws IOException {
    return (char) (br.read());
  }

  String next() throws IOException {
    return nextToken();
  }

  String nextLine() throws IOException {
    return br.readLine();
  }

}


import java.util.*;

public class Main {
	public static void main(String[] z) {
		Scanner s = new Scanner(System.in);
		int n=s.nextInt();
		edges = new ArrayList<List<Integer>>();
		for(int i=0;i<n;++i){
			edges.add(new ArrayList<Integer>());
		}
		for(;n-->1;){
			int u=s.nextInt()-1,v=s.nextInt()-1;
			edges.get(u).add(v);
			edges.get(v).add(u);
		}
		int res=0;
		for(int i=0;i<edges.size();++i){
			for(int t:edges.get(i)){
				res=Math.max(res,maxPath(i,t)[0]*maxPath(t,i)[0]);
			}
		}
		System.out.println(res);
	}
	static List<List<Integer>> edges;
	static int[] maxPath(int v, int prev){
		Integer[] d = {0,0,0};
		int res = 0;
		for(int t:edges.get(v)){
			if(t!=prev){
				int[]r=maxPath(t,v);
				res=Math.max(res,r[0]);
				d[2]=r[1];
				Arrays.sort(d,Collections.reverseOrder());
			}
		}
		res = Math.max(res,d[0]+d[1]);
		return new int[]{res, d[0]+1};
	}
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.*;

public class TwoPaths {
	static class DisjointSet {

		public int[] set;

		public DisjointSet(int n) {
			set = new int[n];
			for (int i = 0; i < set.length; i++) {
				set[i] = i;
			}
		}

		public int find(int x) {
			if (set[x] == x)
				return x;
			return set[x] = find(set[x]);
		}

		public void union(int x, int y) {
			set[find(x)] = find(y);
		}

		public int countDSets() {
			int c = 0;
			for (int i = 0; i < set.length; i++)
				if (set[i] == i)
					c++;
			return c;
		}

	}

	static int rem1;
	static int rem2;

	public static void main(String[] args) throws IOException {
		// TODO Auto-generated method stub
		BufferedReader r = new BufferedReader(new InputStreamReader(System.in));
		String s = r.readLine();
		int n = new Integer(s);
		Vector<Integer>[] adj = new Vector[n];
		for (int i = 0; i < adj.length; i++) {
			adj[i] = new Vector<Integer>();
		}
		Vector<Integer> edges = new Vector<Integer>();
		for (int i = 0; i < n - 1; i++) {
			s = r.readLine();
			String[] sp = s.split(" ");
			int from = new Integer(sp[0]) - 1;
			int to = new Integer(sp[1]) - 1;
			adj[from].add(to);
			adj[to].add(from);
			edges.add(from);
			edges.add(to);
		}
		int max = 0;
		for (int i = 0; i < edges.size(); i += 2) {
			rem1 = edges.get(i);
			rem2 = edges.get(i + 1);
			DisjointSet ds = new DisjointSet(n);
			for (int j = 0; j < edges.size(); j += 2) {
				if (i == j)
					continue;
				ds.union(edges.get(j), edges.get(j + 1));
			}
			HashMap<Integer, Integer> hm = new HashMap<Integer, Integer>();
			int p1 = -1, p2 = -1;

			for (int j = 0; j < n; j++) {
				v=new boolean[n];
				dp=new int[n];
				Arrays.fill(dp, -1);
				v[j]=true;
				int longest = go(j, adj);

				int parent = ds.find(j);
				if (p1 == -1)
					p1 = parent;
				else if(p2==-1&&p1!=parent)
					p2 = parent;
				if (hm.containsKey(parent)) {
					int mx = hm.remove(parent);
					mx = Math.max(mx, longest);
					hm.put(parent, mx);
				} else
					hm.put(parent, longest);
			}
			int product = hm.get(p1) * hm.get(p2);
			max = Math.max(product, max);
		}
		System.out.println(max);
	}
static int[] dp;
static boolean[] v;
	private static int go(int i, Vector<Integer>[] adj) {
		if(dp[i]!=-1){

			return dp[i];
		}
		int max=0;
		for(int x:adj[i]){
			if(!v[x]){
				if(i==rem1&&x==rem2)continue;
				if(i==rem2&&x==rem1)continue;
				v[x]=true;
				max=Math.max(max, 1+go(x,adj));
			}
		}
		return dp[i]=max;
	}
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.*;

public class TwoPaths {
	static class DisjointSet {

		public int[] set;

		public DisjointSet(int n) {
			set = new int[n];
			for (int i = 0; i < set.length; i++) {
				set[i] = i;
			}
		}

		public int find(int x) {
			if (set[x] == x)
				return x;
			return set[x] = find(set[x]);
		}

		public void union(int x, int y) {
			set[find(x)] = find(y);
		}

		public int countDSets() {
			int c = 0;
			for (int i = 0; i < set.length; i++)
				if (set[i] == i)
					c++;
			return c;
		}

	}

	static int rem1;
	static int rem2;

	public static void main(String[] args) throws IOException {
		// TODO Auto-generated method stub
		BufferedReader r = new BufferedReader(new InputStreamReader(System.in));
		String s = r.readLine();
		int n = new Integer(s);
		Vector<Integer>[] adj = new Vector[n];
		for (int i = 0; i < adj.length; i++) {
			adj[i] = new Vector<Integer>();
		}
		Vector<Integer> edges = new Vector<Integer>();
		for (int i = 0; i < n - 1; i++) {
			s = r.readLine();
			String[] sp = s.split(" ");
			int from = new Integer(sp[0]) - 1;
			int to = new Integer(sp[1]) - 1;
			adj[from].add(to);
			adj[to].add(from);
			edges.add(from);
			edges.add(to);
		}
		int max = 0;
		for (int i = 0; i < edges.size(); i += 2) {
			rem1 = edges.get(i);
			rem2 = edges.get(i + 1);
			DisjointSet ds = new DisjointSet(n);
			for (int j = 0; j < edges.size(); j += 2) {
				if (i == j)
					continue;
				ds.union(edges.get(j), edges.get(j + 1));
			}
			HashMap<Integer, Integer> hm = new HashMap<Integer, Integer>();
			int p1 = -1, p2 = -1;

			for (int j = 0; j < n; j++) {
				v = new boolean[n];
				dp = new int[n];
				Arrays.fill(dp, -1);
				v[j] = true;
				int longest = go(j, adj);
				int parent = ds.find(j);
				if (p1 == -1)
					p1 = parent;
				else if (p2 == -1 && p1 != parent)
					p2 = parent;
				if (hm.containsKey(parent)) {
					int mx = hm.remove(parent);
					mx = Math.max(mx, longest);
					hm.put(parent, mx);
				} else
					hm.put(parent, longest);
			}
			int product = hm.get(p1) * hm.get(p2);
			max = Math.max(product, max);
		}
		System.out.println(max);
	}

	static int[] dp;
	static boolean[] v;

	private static int go(int i, Vector<Integer>[] adj) {
//		if (dp[i] != -1) {
//
//			return dp[i];
//		}
		int max = 0;
		for (int x : adj[i]) {
			if (!v[x]) {
				if (i == rem1 && x == rem2)
					continue;
				if (i == rem2 && x == rem1)
					continue;
				v[x] = true;
				max = Math.max(max, 1 + go(x, adj));
			}
		}
		return dp[i] = max;
	}
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.*;

public class TwoPaths {
	static class DisjointSet {

		public int[] set;

		public DisjointSet(int n) {
			set = new int[n];
			for (int i = 0; i < set.length; i++) {
				set[i] = i;
			}
		}

		public int find(int x) {
			if (set[x] == x)
				return x;
			return set[x] = find(set[x]);
		}

		public void union(int x, int y) {
			set[find(x)] = find(y);
		}

		public int countDSets() {
			int c = 0;
			for (int i = 0; i < set.length; i++)
				if (set[i] == i)
					c++;
			return c;
		}

	}

	static int rem1;
	static int rem2;

	public static void main(String[] args) throws IOException {
		// TODO Auto-generated method stub
		BufferedReader r = new BufferedReader(new InputStreamReader(System.in));
		String s = r.readLine();
		int n = new Integer(s);
		Vector<Integer>[] adj = new Vector[n];
		for (int i = 0; i < adj.length; i++) {
			adj[i] = new Vector<Integer>();
		}
		Vector<Integer> edges = new Vector<Integer>();
		for (int i = 0; i < n - 1; i++) {
			s = r.readLine();
			String[] sp = s.split(" ");
			int from = new Integer(sp[0]) - 1;
			int to = new Integer(sp[1]) - 1;
			adj[from].add(to);
			adj[to].add(from);
			edges.add(from);
			edges.add(to);
		}
		int max = 0;
		for (int i = 0; i < edges.size(); i += 2) {
			rem1 = edges.get(i);
			rem2 = edges.get(i + 1);
			DisjointSet ds = new DisjointSet(n);
			for (int j = 0; j < edges.size(); j += 2) {
				if (i == j)
					continue;
				ds.union(edges.get(j), edges.get(j + 1));
			}
			HashMap<Integer, Integer> hm = new HashMap<Integer, Integer>();
			int p1 = -1, p2 = -1;
			for (int j = 0; j < n; j++) {
				int longest = go(j, adj);

				int parent = ds.find(j);
				if (p1 == -1)
					p1 = parent;
				else if(p2==-1&&p1!=parent)
					p2 = parent;
				if (hm.containsKey(parent)) {
					int mx = hm.remove(parent);
					mx = Math.max(mx, longest);
					hm.put(parent, mx);
				} else
					hm.put(parent, longest);
			}
			int product = hm.get(p1) * hm.get(p2);
			max = Math.max(product, max);
		}
		System.out.println(max);
	}

	private static int go(int i, Vector<Integer>[] adj) {
		Queue<Integer> q = new LinkedList<Integer>();
		q.add(i);
		q.add(0);
		int ret = 0;
		boolean[] v = new boolean[adj.length];
		v[i] = true;
		while (!q.isEmpty()) {
			int front = q.remove();
			int co = q.remove();
			ret = co;
			for (int x : adj[front])
				if (!v[x]) {
					if (x == rem1 && front == rem2)
						continue;
					if (x == rem2 && front == rem1)
						continue;
					v[x] = true;
					q.add(x);
					q.add(co + 1);
				}
		}
		return ret;
	}
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.*;

public class TwoPaths {
	static class DisjointSet {

		public int[] set;

		public DisjointSet(int n) {
			set = new int[n];
			for (int i = 0; i < set.length; i++) {
				set[i] = i;
			}
		}

		public int find(int x) {
			if (set[x] == x)
				return x;
			return set[x] = find(set[x]);
		}

		public void union(int x, int y) {
			set[find(x)] = find(y);
		}

		public int countDSets() {
			int c = 0;
			for (int i = 0; i < set.length; i++)
				if (set[i] == i)
					c++;
			return c;
		}

	}

	static int rem1;
	static int rem2;

	public static void main(String[] args) throws IOException {
		// TODO Auto-generated method stub
		BufferedReader r = new BufferedReader(new InputStreamReader(System.in));
		String s = r.readLine();
		int n = new Integer(s);
		Vector<Integer>[] adj = new Vector[n];
		for (int i = 0; i < adj.length; i++) {
			adj[i] = new Vector<Integer>();
		}
		Vector<Integer> edges = new Vector<Integer>();
		for (int i = 0; i < n - 1; i++) {
			s = r.readLine();
			String[] sp = s.split(" ");
			int from = new Integer(sp[0]) - 1;
			int to = new Integer(sp[1]) - 1;
			adj[from].add(to);
			adj[to].add(from);
			edges.add(from);
			edges.add(to);
		}
		int max = 0;
		for (int i = 0; i < edges.size(); i += 2) {
			rem1 = edges.get(i);
			rem2 = edges.get(i + 1);
			DisjointSet ds = new DisjointSet(n);
			for (int j = 0; j < edges.size(); j += 2) {
				if (i == j)
					continue;
				ds.union(edges.get(j), edges.get(j + 1));
			}
			HashMap<Integer, Integer> hm = new HashMap<Integer, Integer>();
			int p1 = -1, p2 = -1;

			for (int j = 0; j < n; j++) {
				v = new boolean[n];

				v[j] = true;
				int longest = go(j, adj);
				int parent = ds.find(j);
				if (p1 == -1)
					p1 = parent;
				else if (p2 == -1 && p1 != parent)
					p2 = parent;
				if (hm.containsKey(parent)) {
					int mx = hm.remove(parent);
					mx = Math.max(mx, longest);
					hm.put(parent, mx);
				} else
					hm.put(parent, longest);
			}
			int product = hm.get(p1) * hm.get(p2);
			max = Math.max(product, max);
		}
		System.out.println(max);
	}

	static boolean[] v;

	private static int go(int i, Vector<Integer>[] adj) {

		int max = 0;
		for (int x : adj[i]) {
			if (!v[x]) {
				if (i == rem1 && x == rem2)
					continue;
				if (i == rem2 && x == rem1)
					continue;
				v[x] = true;
				max = Math.max(max, 1 + go(x, adj));
			}
		}
		return max;
	}
}


//package d14;
import java.util.*;
import java.io.*;

public class Main {

	BufferedReader in;
	StringTokenizer str = null;

	private int nextInt() throws Exception{
		if (str == null || !str.hasMoreElements())
			str = new StringTokenizer(in.readLine());
		return Integer.parseInt(str.nextToken());
	}
	LinkedList<Integer> l[];
	boolean [][]g,f;
	int n;
	boolean []used;

	public void run() throws Exception{
		in = new BufferedReader(new InputStreamReader(System.in));//(new FileReader("input.txt"));
		n = nextInt();
		if (n<=3){
			System.out.println(0);
			return;
		}
		l = new LinkedList[n];
		for(int i=0;i<n;i++) l[i] = new LinkedList<Integer>();
		g = new boolean[n][n];
		f = new boolean[n][n];

		for(int i=0;i<n-1;i++){
			int x = nextInt()-1;
			int y = nextInt()-1;
			l[x].add(y);
			l[y].add(x);
			g[x][y] = g[y][x] = true;
		}

		int ret = 0;

		for(int i=0;i<n;i++){
			for(int j:l[i])if (!f[i][j]){
				f[i][j] = f[j][i] = true;
				g[i][j] = g[j][i] = false;
				used = new boolean[n];

				int x = dfs(i,i)-1;
				int y = dfs(j,j)-1;

				if (ret < x*y) ret = x*y;

				g[i][j] = g[j][i] = true;
			}
		}
		System.out.println(ret);
	}

	private int dfs(int x, int y){
		used[x] = true;
		int leaf = 0;
		int index = -1;

		for(int i:l[x]){
			if (g[x][i] && !used[i]){
				leaf++;
				index = i;
			}
		}

		if (leaf == 0) return 1;
		if (leaf == 1) return 1+dfs(index, y);

		int r = -1, h = -1;
		for(int i:l[x]){
			if (g[x][i] && !used[i]){
				int t = dfs(i,y);
				if (r == -1) r = t;
				else if (h == -1) h = t;
				else{
					int b[] = new int[]{r,t,h};
					Arrays.sort(b);
					r = b[1];
					h = b[2];
				}
			}
		}
		if (x == y) return r+h+1;
		return Math.max(r,h)+1;
	}

	public static void main(String args[]) throws Exception{
		new Main().run();
	}
}


//package d14;
import java.util.*;
import java.io.*;

public class Main {

	BufferedReader in;
	StringTokenizer str = null;

	private int nextInt() throws Exception{
		if (str == null || !str.hasMoreElements())
			str = new StringTokenizer(in.readLine());
		return Integer.parseInt(str.nextToken());
	}
	LinkedList<Integer> l[];
	boolean [][]g,f;
	int n;
	boolean []used;

	public void run() throws Exception{
		in = new BufferedReader(new InputStreamReader(System.in));//(new FileReader("input.txt"));//
		n = nextInt();
		l = new LinkedList[n];
		for(int i=0;i<n;i++) l[i] = new LinkedList<Integer>();
		g = new boolean[n][n];
		f = new boolean[n][n];

		for(int i=0;i<n-1;i++){
			int x = nextInt()-1;
			int y = nextInt()-1;
			l[x].add(y);
			l[y].add(x);
			g[x][y] = g[y][x] = true;
		}

		int ret = 0;

		for(int i=0;i<n;i++){
			for(int j:l[i]){
				f[i][j] = f[j][i] = true;
				g[i][j] = g[j][i] = false;
				used = new boolean[n];

				dfs(i);
				int x = findDiametr();
				leaf.clear();
				dfs(j);
				int y = findDiametr();
				leaf.clear();

				if (ret < x*y) ret = x*y;

				g[i][j] = g[j][i] = true;
			}
		}
		System.out.println(ret);
	}
	LinkedList<Integer> leaf = new LinkedList<Integer>();

	private int findDiametr(){
		int max = Integer.MIN_VALUE;
		for(int i:leaf){

			Queue<Integer> q = new LinkedList<Integer>();
			int d[] = new int[n];
			Arrays.fill(d, Integer.MAX_VALUE/2);
			d[i] = 0;
			q.add(i);
			while(q.size() > 0){
				int cur = q.poll();
				for(int j:l[cur])
					if (g[cur][j] && d[j] > d[cur] + 1){
						d[j] = d[cur] + 1;
						q.add(j);
					}
			}
			for(int j=0;j<n;j++)
				if (d[j]!=Integer.MAX_VALUE/2) max = Math.max(max, d[j]);

		}
		return max;

	}

	private void dfs(int x){
		used[x] = true;
		boolean found = false;
		for(int i:l[x]){
			if (!used[i] && g[x][i]){
				found = true;
				dfs(i);
			}
		}
		if (!found) leaf.add(x);
	}

	public static void main(String args[]) throws Exception{
		new Main().run();
	}
}


//package d14;
import java.util.*;
import java.io.*;

public class Main {

	BufferedReader in;
	StringTokenizer str = null;

	private int nextInt() throws Exception{
		if (str == null || !str.hasMoreElements())
			str = new StringTokenizer(in.readLine());
		return Integer.parseInt(str.nextToken());
	}
	LinkedList<Integer> l[];
	boolean [][]g,f;
	int n;
	boolean []used;

	public void run() throws Exception{
		in = new BufferedReader(new InputStreamReader(System.in));//(new FileReader("input.txt"));//
		n = nextInt();
		l = new LinkedList[n];
		for(int i=0;i<n;i++) l[i] = new LinkedList<Integer>();
		g = new boolean[n][n];
		f = new boolean[n][n];

		for(int i=0;i<n-1;i++){
			int x = nextInt()-1;
			int y = nextInt()-1;
			l[x].add(y);
			l[y].add(x);
			g[x][y] = g[y][x] = true;
		}

		int ret = 0;

		for(int i=0;i<n;i++){
			for(int j:l[i])if (!f[i][j]){
				f[i][j] = f[j][i] = true;
				g[i][j] = g[j][i] = false;
				used = new boolean[n];

				dfs(i);
				int x = findDiametr();
				leaf.clear();
				dfs(j);
				int y = findDiametr();
				leaf.clear();

				if (ret < x*y) ret = x*y;

				g[i][j] = g[j][i] = true;
			}
		}
		System.out.println(ret);
	}
	LinkedList<Integer> leaf = new LinkedList<Integer>();

	private int findDiametr(){
		int max = Integer.MIN_VALUE;
		for(int i:leaf){

			Queue<Integer> q = new LinkedList<Integer>();
			int d[] = new int[n];
			Arrays.fill(d, Integer.MAX_VALUE/2);
			d[i] = 0;
			q.add(i);
			while(q.size() > 0){
				int cur = q.poll();
				for(int j:l[cur])
					if (g[cur][j] && d[j] > d[cur] + 1){
						d[j] = d[cur] + 1;
						q.add(j);
					}
			}
			for(int j=0;j<n;j++)
				if (d[j]!=Integer.MAX_VALUE/2) max = Math.max(max, d[j]);

		}
		return max;

	}

	private void dfs(int x){
		used[x] = true;
		boolean found = false;
		for(int i:l[x]){
			if (!used[i] && g[x][i]){
				found = true;
				dfs(i);
			}
		}
		if (!found) leaf.add(x);
	}

	public static void main(String args[]) throws Exception{
		new Main().run();
	}
}


import java.util.*;
import java.io.*;
public class Main{

        BufferedReader in;
        StringTokenizer str = null;
        PrintWriter out;

        private String next() throws Exception{
                if (str == null || !str.hasMoreTokens())
                        str = new StringTokenizer(in.readLine());
                return str.nextToken();
        }

        private int nextInt() throws Exception{
                return Integer.parseInt(next());
        }

        private long nextLong() throws Exception{
                return Long.parseLong(next());
        }

        private double nextDouble() throws Exception{
                return Double.parseDouble(next());
        }
        LinkedList<Integer> l[];
        boolean [][]g,fin;
        int n,ans=0;
        boolean used[];

        public void run() throws Exception{
                in = new BufferedReader(new InputStreamReader(System.in));//new FileReader();
                out = new PrintWriter(System.out);//new File();
                n = nextInt();
                l = new LinkedList[n];
                for(int i=0;i<n;i++) l[i] = new LinkedList<Integer>();
                g = new boolean[n][n];
                fin = new boolean[n][n];

                for(int i=0;i<n-1;i++){
                  int x = nextInt()-1;
                  int y = nextInt()-1;
                  g[x][y] = true;
                  g[y][x] = true;
                  l[x].add(y);
                  l[y].add(x);
                }

                for(int i=0;i<n;i++){
                  for(int j:l[i])if (!fin[i][j]){
                    g[i][j] = false;
                    g[j][i] = false;
                    fin[i][j] = true;
                    fin[j][i] = true;
                    used = new boolean[n];

                    int first = dfs(i,i)-1;
                    int second = dfs(j,j)-1;

                    //out.println(i + " " + j + " " + first + " " + second);

                    ans = Math.max(first*second, ans);

                    g[i][j] = true;
                    g[j][i] = true;
                  }
                }
                out.println(ans);
                out.close();
        }

        private int dfs(int x, int p){
          used[x] = true;
          int leaf = 0;
          int index = -1;
          for(int i:l[x]) if (g[x][i] && !used[i]){
             leaf++;
             index = i;
          }
          if (leaf == 0) return 1;
          if (leaf == 1){
            return 1 + dfs(index,p);
          }else{
            int left = -1;
            int right = -1;
            for(int i:l[x]){
              if (!used[i] && g[x][i]){
                int t = dfs(i,p);
                if (left == -1) left = t;
                else if (right == -1) right = t;
                else{
                  int temp[] = new int[3];
                  temp[0] = left;
                  temp[1] = right;
                  temp[2] = t;
                  Arrays.sort(temp);
                  left = temp[1];
                  right = temp[2];
                }
              }
            }
            if (x == p) return left+right+1;
            else return Math.max(left, right)+1;
          }
        }

        public static void main(String args[]) throws Exception{
                new Main().run();
        }
}


//package d14;
import java.util.*;
import java.io.*;

public class Main {

        BufferedReader in;
        StringTokenizer str = null;

        private int nextInt() throws Exception{
                if (str == null || !str.hasMoreElements())
                        str = new StringTokenizer(in.readLine());
                return Integer.parseInt(str.nextToken());
        }
        LinkedList<Integer> l[];
        boolean [][]g,f;
        int n;
        boolean []used;

        public void run() throws Exception{
                in = new BufferedReader(new InputStreamReader(System.in));//(new FileReader("input.txt"));//
                n = nextInt();
                l = new LinkedList[n];
                for(int i=0;i<n;i++) l[i] = new LinkedList<Integer>();
                g = new boolean[n][n];
                f = new boolean[n][n];

                for(int i=0;i<n-1;i++){
                        int x = nextInt()-1;
                        int y = nextInt()-1;
                        l[x].add(y);
                        l[y].add(x);
                        g[x][y] = g[y][x] = true;
                }

                int ret = 0;

                for(int i=0;i<n;i++){
                        for(int j:l[i])if (!f[i][j]){
                                f[i][j] = f[j][i] = true;
                                g[i][j] = g[j][i] = false;
                                used = new boolean[n];

                                int x = dfs(i,i)-1;
                                int y = dfs(j,j)-1;

                                if (ret < x*y) ret = x*y;

                                g[i][j] = g[j][i] = true;
                        }
                }
                System.out.println(ret);
        }

        private int dfs(int x, int y){
                used[x] = true;
                int leaf = 0;
                int index = -1;

                for(int i:l[x]){
                        if (g[x][i] && !used[i]){
                                leaf++;
                                index = i;
                        }
                }
                if (leaf == 0) return 1;
                if (leaf == 1) return 1+dfs(index, y);

                int r = -1, h = -1;
                for(int i:l[x]){
                        if (g[x][i] && !used[i]){
                                int t = dfs(i,y);
                                if (t > r) {
                                	h = r;
                                	r = t;
                                }else if (t > h) h = t;
                        }
                }
                if (x == y) return r+h+1;
                return Math.max(r,h)+1;
        }

        public static void main(String args[]) throws Exception{
                new Main().run();
        }
}


import java.util.*;
import java.io.*;
public class Main{

        BufferedReader in;
        StringTokenizer str = null;
        PrintWriter out;

        private String next() throws Exception{
                if (str == null || !str.hasMoreTokens())
                        str = new StringTokenizer(in.readLine());
                return str.nextToken();
        }

        private int nextInt() throws Exception{
                return Integer.parseInt(next());
        }

        private long nextLong() throws Exception{
                return Long.parseLong(next());
        }

        private double nextDouble() throws Exception{
                return Double.parseDouble(next());
        }
        LinkedList<Integer> l[];
        boolean [][]g,fin;
        int n,ans=0;
        boolean used[];

        public void run() throws Exception{
                in = new BufferedReader(new InputStreamReader(System.in));//new FileReader();
                out = new PrintWriter(System.out);//new File();
                n = nextInt();
                l = new LinkedList[n];
                for(int i=0;i<n;i++) l[i] = new LinkedList<Integer>();
                g = new boolean[n][n];
                fin = new boolean[n][n];

                for(int i=0;i<n-1;i++){
                  int x = nextInt()-1;
                  int y = nextInt()-1;
                  g[x][y] = true;
                  g[y][x] = true;
                  l[x].add(y);
                  l[y].add(x);
                }

                for(int i=0;i<n;i++){
                  for(int j:l[i])if (!fin[i][j]){
                    g[i][j] = false;
                    g[j][i] = false;
                    fin[i][j] = true;
                    fin[j][i] = true;
                    used = new boolean[n];

                    int first = dfs(i)-1;
                    int second = dfs(j)-1;

                    //out.println(i + " " + j + " " + first + " " + second);

                    ans = Math.max(first*second, ans);

                    g[i][j] = true;
                    g[j][i] = true;
                  }
                }
                out.println(ans);
                out.close();
        }

        private int dfs(int x){
          used[x] = true;
          int ret = 0;
          for(int i:l[x])
            if (g[x][i] && !used[i]) ret+=dfs(i);

          return 1+ret;
        }

        public static void main(String args[]) throws Exception{
                new Main().run();
        }
}


import java.util.*;
import java.io.*;
public class Main{

        BufferedReader in;
        StringTokenizer str = null;
        PrintWriter out;

        private String next() throws Exception{
                if (str == null || !str.hasMoreTokens())
                        str = new StringTokenizer(in.readLine());
                return str.nextToken();
        }

        private int nextInt() throws Exception{
                return Integer.parseInt(next());
        }

        private long nextLong() throws Exception{
                return Long.parseLong(next());
        }

        private double nextDouble() throws Exception{
                return Double.parseDouble(next());
        }
        LinkedList<Integer> l[];
        boolean [][]g;
        int n,ans=0;
        boolean used[];

        public void run() throws Exception{
                in = new BufferedReader(new InputStreamReader(System.in));//new FileReader();
                out = new PrintWriter(System.out);//new File();
                n = nextInt();
                l = new LinkedList[n];
                for(int i=0;i<n;i++) l[i] = new LinkedList<Integer>();
                g = new boolean[n][n];

                for(int i=0;i<n-1;i++){
                  int x = nextInt()-1;
                  int y = nextInt()-1;
                  g[x][y] = true;
                  g[y][x] = true;
                  l[x].add(y);
                  l[y].add(x);
                }

                for(int i=0;i<n;i++){
                  for(int j:l[i]){
                    g[i][j] = false;
                    g[j][i] = false;
                    used = new boolean[n];

                    int first = dfs(i,i)-1;
                    int second = dfs(j,j)-1;

                    //out.println(i + " " + j + " " + first + " " + second);

                    ans = Math.max(first*second, ans);

                    g[i][j] = true;
                    g[j][i] = true;
                  }
                }
                out.println(ans);
                out.close();
        }

        private int dfs(int x, int p){
          used[x] = true;
          int leaf = 0;
          int index = -1;
          for(int i:l[x]) if (g[x][i] && !used[i]){
             leaf++;
             index = i;
          }
          if (leaf == 0) return 1;
          if (leaf == 1) return 1 + dfs(index,p);

          int left = -1;
          int right = -1;
          for(int i:l[x]){
            if (!used[i] && g[x][i]){
              int t = dfs(i,p);
              if (left == -1) left = t;
              else if (right == -1) right = t;
              else{
                int temp[] = new int[3];
                temp[0] = left;
                temp[1] = right;
                temp[2] = t;
                Arrays.sort(temp);
                left = temp[1];
                right = temp[2];
              }
            }
          }
          if (x == p) return left+right+1;
          else return Math.max(left, right)+1;
        }

        public static void main(String args[]) throws Exception{
                new Main().run();
        }
}


//package d14;
import java.util.*;
import java.io.*;

public class Main {

        BufferedReader in;
        StringTokenizer str = null;

        private int nextInt() throws Exception{
                if (str == null || !str.hasMoreElements())
                        str = new StringTokenizer(in.readLine());
                return Integer.parseInt(str.nextToken());
        }
        LinkedList<Integer> l[];
        boolean [][]g,f;
        int n;
        boolean []used;

        public void run() throws Exception{
                in = new BufferedReader(new InputStreamReader(System.in));//(new FileReader("input.txt"));//
                n = nextInt();
                l = new LinkedList[n];
                for(int i=0;i<n;i++) l[i] = new LinkedList<Integer>();
                g = new boolean[n][n];
                f = new boolean[n][n];

                for(int i=0;i<n-1;i++){
                        int x = nextInt()-1;
                        int y = nextInt()-1;
                        l[x].add(y);
                        l[y].add(x);
                        g[x][y] = g[y][x] = true;
                }

                int ret = 0;

                for(int i=0;i<n;i++){
                        for(int j:l[i])if (!f[i][j]){
                                f[i][j] = f[j][i] = true;
                                g[i][j] = g[j][i] = false;
                                used = new boolean[n];

                                int x = dfs(i,i)-1;
                                int y = dfs(j,j)-1;

                                if (ret < x*y) ret = x*y;

                                g[i][j] = g[j][i] = true;
                        }
                }
                System.out.println(ret);
        }

        private int dfs(int x, int y){
                used[x] = true;
                int leaf = 0;
                int index = -1;

                for(int i:l[x]){
                        if (g[x][i] && !used[i]){
                                leaf++;
                                index = i;
                        }
                }
                if (leaf == 0) return 1;
                if (leaf == 1) return 1+dfs(index, y);

                int r = -1, h = -1;
                for(int i:l[x]){
                        if (g[x][i] && !used[i]){
                                int t = dfs(i,y);
                                if (t > r) {
                                	h = r;
                                	r = t;
                                }else if (t > h) h = t;
                        }
                }
                return r+h+1;
        }

        public static void main(String args[]) throws Exception{
                new Main().run();
        }
}


//package d14;
import java.util.*;
import java.io.*;

public class Main {

	BufferedReader in;
	StringTokenizer str = null;

	private int nextInt() throws Exception{
		if (str == null || !str.hasMoreElements())
			str = new StringTokenizer(in.readLine());
		return Integer.parseInt(str.nextToken());
	}
	LinkedList<Integer> l[];
	boolean [][]g,f;
	int n;
	boolean []used;

	public void run() throws Exception{
		in = new BufferedReader(new InputStreamReader(System.in));//(new FileReader("input.txt"));
		n = nextInt();
		l = new LinkedList[n];
		for(int i=0;i<n;i++) l[i] = new LinkedList<Integer>();
		g = new boolean[n][n];
		f = new boolean[n][n];

		for(int i=0;i<n-1;i++){
			int x = nextInt()-1;
			int y = nextInt()-1;
			l[x].add(y);
			l[y].add(x);
			g[x][y] = g[y][x] = true;
		}

		int ret = 0;

		for(int i=0;i<n;i++){
			for(int j:l[i])if (!f[i][j]){
				f[i][j] = f[j][i] = true;
				g[i][j] = g[j][i] = false;
				used = new boolean[n];

				int x = dfs(i,i)-1;
				int y = dfs(j,j)-1;

				if (ret < x*y) ret = x*y;

				g[i][j] = g[j][i] = true;
			}
		}
		System.out.println(ret);
	}

	private int dfs(int x, int y){
		used[x] = true;
		int leaf = 0;
		int index = -1;

		for(int i:l[x]){
			if (g[x][i] && !used[i]){
				leaf++;
				index = i;
			}
		}

		if (leaf == 0) return 1;
		if (leaf == 1) return 1+dfs(index, y);

		int r = -1, h = -1;
		for(int i:l[x]){
			if (g[x][i] && !used[i]){
				int t = dfs(i,y);
				if (r == -1) r = t;
				else if (h == -1) h = t;
				else{
					int b[] = new int[]{r,t,h};
					Arrays.sort(b);
					r = b[1];
					h = b[2];
				}
			}
		}
		if (x == y) return r+h+1;
		return Math.max(r,h)+1;
	}

	public static void main(String args[]) throws Exception{
		new Main().run();
	}
}


import java.util.ArrayList;
import java.util.Arrays;
import java.util.Scanner;

public class D14 {
    static ArrayList<Integer>[]ages;
    static int[]depth;

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        ages = new ArrayList[n+1];
        for (int i = 1; i <= n; i++) {
            ages[i] = new ArrayList<Integer>();
        }
        for (int i = 1; i < n; i++) {
            int v1 = sc.nextInt();
            int v2 = sc.nextInt();
            ages[v1].add(v2);
            ages[v2].add(v1);
        }
        int max = 0;
        depth = new int[n+1];
        for (int i = 1; i <= n; i++) {
            for (int j : ages[i]) {
                int L1 = try_calc(i, j);
                int L2 = try_calc(j, i);
                max = Math.max(max, L1*L2);
            }
        }
        System.out.println(max);
    }

    private static int try_calc(int i, int j) {
        Arrays.fill(depth, 0);
        dfs(i, j);
        int max1 = 0,max2 = 0;
        for (int v : ages[i]) {
            if (v==j)
                continue;
            if (depth[v]+1 > max1) {
                max2 = max1;
                max1 = depth[v]+1;
            }
            else if (depth[v]+1 > max2) {
                max2 = depth[v]+1;
            }
        }
        return max1+max2;
    }

    private static void dfs(int v, int p) {
        for (int to : ages[v]) {
            if (to==p)
                continue;
            dfs(to, v);
            depth[v] = Math.max(depth[v], depth[to]+1);
        }
    }
}


import java.util.ArrayList;
import java.util.Scanner;

public class D14 {
    static int INF = (int) 1e9;
    static int max = 0, n;
    static int[]sons;
    static ArrayList<Integer>[]ages;

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        n = sc.nextInt();
        ages = new ArrayList[n+1];
        for (int i = 1; i <= n; i++) {
            ages[i] = new ArrayList<Integer>();
        }
        for (int i = 1; i < n; i++) {
            int v1 = sc.nextInt();
            int v2 = sc.nextInt();
            ages[v1].add(v2);
            ages[v2].add(v1);
        }
        sons = new int[n+1];
        dfs(1, 0);
        System.out.println(max);
    }

    private static void dfs(int v, int p) {
        for (int to : ages[v]) {
            if (to==p)
                continue;
            dfs(to, v);
        }
        for (int to : ages[v]) {
            if (to != p) {
                sons[v] += sons[to];
            }
        }
        sons[v]++;
        max = Math.max((sons[v]-1)*(n-sons[v]-1), max);
    }
}


import java.util.ArrayList;
import java.util.Arrays;
import java.util.Scanner;

public class D14 {
    static ArrayList<Integer>[]ages;
    static int[]depth;
    static int sum_max;

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        ages = new ArrayList[n+1];
        for (int i = 1; i <= n; i++) {
            ages[i] = new ArrayList<Integer>();
        }
        for (int i = 1; i < n; i++) {
            int v1 = sc.nextInt();
            int v2 = sc.nextInt();
            ages[v1].add(v2);
            ages[v2].add(v1);
        }
        int max = 0;
        depth = new int[n+1];
        boolean[][]used = new boolean[n+1][n+1];
        for (int i = 1; i <= n; i++) {
            for (int j : ages[i]) {
                if (used[i][j])
                    continue;
                used[i][j] = used[j][i] = true;
                int L1 = try_calc(i, j);
                int L2 = try_calc(j, i);
                max = Math.max(max, L1*L2);
            }
        }
        System.out.println(max);
    }

    private static int try_calc(int i, int j) {
        Arrays.fill(depth, 0);
        sum_max = 0;
        dfs(i, j);
        return sum_max;
    }

    private static void dfs(int v, int p) {
        for (int to : ages[v]) {
            if (to==p)
                continue;
            dfs(to, v);
            depth[v] = Math.max(depth[v], depth[to]+1);
        }
        int max1 = 0,max2 = 0;
        for (int i : ages[v]) {
            if (i==p)
                continue;
            if (depth[i]+1 > max1) {
                max2 = max1;
                max1 = depth[i]+1;
            }
            else if (depth[i]+1 > max2) {
                max2 = depth[i]+1;
            }
        }
        sum_max = Math.max(sum_max, max1+max2);
    }
}


import java.util.ArrayList;
import java.util.Arrays;
import java.util.Scanner;

public class D {

    static ArrayList<Integer>[] ages;
    static boolean[]used;
    static int[]d;

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        ages = new ArrayList[n+1];
        for (int i = 1; i <= n; i++) {
            ages[i] = new ArrayList<Integer>();
        }
        int[]v1 = new int[n], v2 = new int[n];
        for (int i = 1; i < n; i++) {
            v1[i] = sc.nextInt();
            v2[i] = sc.nextInt();
            ages[v1[i]].add(v2[i]);
            ages[v2[i]].add(v1[i]);
        }
        used = new boolean[n+1];
        d = new int[n+1];
        int ans = 0;
        for (int i = 1; i < n; i++) {
            Arrays.fill(used, false);
            Arrays.fill(d, 0);
            ages[v1[i]].remove(ages[v1[i]].indexOf(v2[i]));
            ages[v2[i]].remove(ages[v2[i]].indexOf(v1[i]));
            dfs(v1[i]);
            int k1 = 0;
            for (int j = 1; j <= n; j++) {
                if (d[j] > d[k1])
                    k1 = j;
            }
            int k2 = 0;
            for (int j = 1; j <= n; j++) {
                if (d[j] > d[k2] && k1 != j)
                    k2 = j;
            }
            int max1 = d[k1]+d[k2];
            Arrays.fill(d, 0);
            dfs(v2[i]);
            k1 = 0;
            for (int j = 1; j <= n; j++) {
                if (d[j] > d[k1])
                    k1 = j;
            }
            k2 = 0;
            for (int j = 1; j <= n; j++) {
                if (d[j] > d[k2] && k1 != j)
                    k2 = j;
            }
            int max2 = d[k1]+d[k2];
            ans = Math.max(ans, max1*max2);
            ages[v1[i]].add(v2[i]);
            ages[v2[i]].add(v1[i]);
        }
        System.out.println(ans);
    }

    private static void dfs(int v) {
        used[v] = true;
        for (int to : ages[v]) {
            if (!used[to]) {
                d[to] = d[v]+1;
                dfs(to);
            }
        }
    }
}


import java.util.Arrays;
import java.util.LinkedList;
import java.util.Queue;
import java.util.Scanner;
import java.util.Vector;

public class Task14d {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		boolean[][] tree = new boolean[n][n];
		for (int i = 0; i < n; i++) {
			Arrays.fill(tree[i], false);
		}
		int ways[][] = new int[n-1][2];
		for (int i = 0; i < n - 1; i++) {
			ways[i][0] = sc.nextInt() - 1;
			ways[i][1] = sc.nextInt() - 1;
			tree[ways[i][0]][ways[i][1]] = true;
			tree[ways[i][1]][ways[i][0]] = true;
		}
		int best = 0;
		for (int i = 0; i < n-1; i++) {
			tree[ways[i][0]][ways[i][1]] = false;
			tree[ways[i][1]][ways[i][0]] = false;
			Queue<Integer> q = new LinkedList<Integer>();
			Vector<Integer> first = new Vector<Integer>();
			q.add(0);
			first.add(0);
			boolean[] vis = new boolean[n];
			Arrays.fill(vis, false);
			while (!q.isEmpty()) {
				int curr = q.poll();
				vis[curr] = true;
				for (int k = 0; k < n; k++) {
					if (vis[k]) continue;
					if (tree[curr][k]) {
						q.add(k);
						first.add(k);
					}
				}
			}
			if (first.size() == 1 || first.size() == n - 1) {
				tree[ways[i][0]][ways[i][1]] = true;
				tree[ways[i][1]][ways[i][0]] = true;
				continue;
			}
			Vector<Integer> second = new Vector<Integer>();
			for (int j = 0; j < n; j++) {
				if (!vis[j]) second.add(j);
			}
			int firstbest = 0;
			for (int curr : first) {
				q.clear();
				q.add(curr);
				int dist[] = new int[n];
				Arrays.fill(dist, 1000);
				dist[curr] = 0;
				while (!q.isEmpty()) {
					int cv = q.poll();
					for (int next: first) {
						if (tree[cv][next]) {
							if (dist[next] < dist[cv]) continue;
							q.add(next);
							dist[next] = dist[cv] + 1;
						}
					}
				}
				for (int j = 0; j < n; j++) {
					if (dist[j] == 1000) continue;
					if (firstbest < dist[j]) firstbest = dist[j];
				}
			}

			int secondbest = 0;
			for (int curr : second) {
				q.clear();
				q.add(curr);
				int dist[] = new int[n];
				Arrays.fill(dist, 1000);
				dist[curr] = 0;
				while (!q.isEmpty()) {
					int cv = q.poll();
					for (int next: second) {
						if (tree[cv][next]) {
							if (dist[next] < dist[cv]) continue;
							q.add(next);
							dist[next] = dist[cv] + 1;
						}
					}
				}
				for (int j = 0; j < n; j++) {
					if (dist[j] == 1000) continue;
					if (secondbest < dist[j]) secondbest = dist[j];
				}
			}
			if (best < firstbest*secondbest) best = firstbest*secondbest;

			tree[ways[i][0]][ways[i][1]] = true;
			tree[ways[i][1]][ways[i][0]] = true;
		}
		System.out.println(best);
	}

}


import java.util.Arrays;
import java.util.LinkedList;
import java.util.Queue;
import java.util.Scanner;
import java.util.Vector;

public class Task14d {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		boolean[][] tree = new boolean[n][n];
		for (int i = 0; i < n; i++) {
			Arrays.fill(tree[i], false);
		}
		int ways[][] = new int[n-1][2];
		for (int i = 0; i < n - 1; i++) {
			ways[i][0] = sc.nextInt() - 1;
			ways[i][1] = sc.nextInt() - 1;
			tree[ways[i][0]][ways[i][1]] = true;
			tree[ways[i][1]][ways[i][0]] = true;
		}
		int best = 0;
		for (int i = 0; i < n-1; i++) {
			tree[ways[i][0]][ways[i][1]] = false;
			tree[ways[i][1]][ways[i][0]] = false;
			Queue<Integer> q = new LinkedList<Integer>();
			Vector<Integer> first = new Vector<Integer>();
			q.add(0);
			first.add(0);
			boolean[] vis = new boolean[n];
			Arrays.fill(vis, false);
			while (!q.isEmpty()) {
				int curr = q.poll();
				vis[curr] = true;
				for (int k = 0; k < n; k++) {
					if (vis[k]) continue;
					if (tree[curr][k]) {
						q.add(k);
						first.add(k);
					}
				}
			}
			if (first.size() == 1 || first.size() == n - 1) {
				tree[ways[i][0]][ways[i][1]] = true;
				tree[ways[i][1]][ways[i][0]] = true;
				continue;
			}
			Vector<Integer> second = new Vector<Integer>();
			for (int j = 0; j < n; j++) {
				if (!vis[j]) second.add(j);
			}
			if (best >= (first.size()-1) * (second.size()-1)) {
				tree[ways[i][0]][ways[i][1]] = true;
				tree[ways[i][1]][ways[i][0]] = true;
				continue;
			}
			int firstbest = 0;
			for (int curr : first) {
				q.clear();
				q.add(curr);
				int dist[] = new int[n];
				Arrays.fill(dist, 1000);
				dist[curr] = 0;
				while (!q.isEmpty()) {
					int cv = q.poll();
					for (int next: first) {
						if (tree[cv][next]) {
							if (dist[next] < dist[cv]) continue;
							q.add(next);
							dist[next] = dist[cv] + 1;
						}
					}
				}
				for (int j = 0; j < n; j++) {
					if (dist[j] == 1000) continue;
					if (firstbest < dist[j]) firstbest = dist[j];
				}
			}

			if (best >= firstbest * (second.size()-1)) {
				tree[ways[i][0]][ways[i][1]] = true;
				tree[ways[i][1]][ways[i][0]] = true;
				continue;
			}

			int secondbest = 0;
			for (int curr : second) {
				q.clear();
				q.add(curr);
				int dist[] = new int[n];
				Arrays.fill(dist, 1000);
				dist[curr] = 0;
				while (!q.isEmpty()) {
					int cv = q.poll();
					for (int next: second) {
						if (tree[cv][next]) {
							if (dist[next] < dist[cv]) continue;
							q.add(next);
							dist[next] = dist[cv] + 1;
						}
					}
				}
				for (int j = 0; j < n; j++) {
					if (dist[j] == 1000) continue;
					if (secondbest < dist[j]) secondbest = dist[j];
				}
			}
			if (best < firstbest*secondbest) best = firstbest*secondbest;

			tree[ways[i][0]][ways[i][1]] = true;
			tree[ways[i][1]][ways[i][0]] = true;
		}
		System.out.println(best);
	}

}


import java.util.Arrays;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.Queue;
import java.util.Scanner;
import java.util.Vector;

public class Task14d {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		HashSet<Integer> nei[] = new HashSet[n];
		for (int i = 0; i < n; i++) {
			nei[i] = new HashSet<Integer>();
		}

		int ways[][] = new int[n-1][2];
		for (int i = 0; i < n - 1; i++) {
			ways[i][0] = sc.nextInt() - 1;
			ways[i][1] = sc.nextInt() - 1;
			nei[ways[i][0]].add(ways[i][1]);
			nei[ways[i][1]].add(ways[i][0]);
		}
		int best = 0;
		for (int i = 0; i < n-1; i++) {
			nei[ways[i][0]].remove(ways[i][1]);
			nei[ways[i][1]].remove(ways[i][0]);
			Queue<Integer> q = new LinkedList<Integer>();
			Vector<Integer> first = new Vector<Integer>();
			q.add(0);
			first.add(0);
			boolean[] vis = new boolean[n];
			Arrays.fill(vis, false);
			while (!q.isEmpty()) {
				int curr = q.poll();
				vis[curr] = true;
				for (Iterator<Integer> it = nei[curr].iterator(); it.hasNext(); ) {
					int k = it.next();
					if (vis[k]) continue;
					q.add(k);
					first.add(k);
				}
			}
			if (first.size() == 1 || first.size() == n - 1) {
				nei[ways[i][0]].add(ways[i][1]);
				nei[ways[i][1]].add(ways[i][0]);
				continue;
			}
			Vector<Integer> second = new Vector<Integer>();
			for (int j = 0; j < n; j++) {
				if (!vis[j]) second.add(j);
			}
			if (best >= (first.size()-1) * (second.size()-1)) {
				nei[ways[i][0]].add(ways[i][1]);
				nei[ways[i][1]].add(ways[i][0]);
				continue;
			}
			int firstbest = 0;
			for (int curr : first) {
				q.clear();
				q.add(curr);
				int dist[] = new int[n];
				Arrays.fill(dist, 1000);
				dist[curr] = 0;
				while (!q.isEmpty()) {
					int cv = q.poll();
					for (Iterator<Integer> it = nei[cv].iterator(); it.hasNext(); ) {
						int next = it.next();
						if (dist[next] < dist[cv]) continue;
						q.add(next);
						dist[next] = dist[cv] + 1;
					}
				}
				for (int j : first) {
					if (dist[j] == 1000) continue;
					if (firstbest < dist[j]) firstbest = dist[j];
				}
			}

			if (best >= firstbest * (second.size()-1)) {
				nei[ways[i][0]].add(ways[i][1]);
				nei[ways[i][1]].add(ways[i][0]);
				continue;
			}

			int secondbest = 0;
			for (int curr : second) {
				q.clear();
				q.add(curr);
				int dist[] = new int[n];
				Arrays.fill(dist, 1000);
				dist[curr] = 0;
				while (!q.isEmpty()) {
					int cv = q.poll();
					for (Iterator<Integer> it = nei[cv].iterator(); it.hasNext(); ) {
						int next = it.next();
						if (dist[next] < dist[cv]) continue;
						q.add(next);
						dist[next] = dist[cv] + 1;
					}
				}
				for (int j : second) {
					if (dist[j] == 1000) continue;
					if (secondbest < dist[j]) secondbest = dist[j];
				}
			}
			if (best < firstbest*secondbest) best = firstbest*secondbest;

			nei[ways[i][0]].add(ways[i][1]);
			nei[ways[i][1]].add(ways[i][0]);
		}
		System.out.println(best);
	}

}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Locale;
import java.util.StringTokenizer;

public class Solution implements Runnable {

    public static void main(String[] args) {
        (new Thread(new Solution())).start();
    }

    BufferedReader in;
    PrintWriter out;
    StringTokenizer st;

    String nextToken() throws IOException {
        while (st == null || !st.hasMoreTokens()) st = new StringTokenizer(in.readLine());
        return st.nextToken();
    }

    int nextInt() throws IOException {
        return Integer.parseInt(nextToken());
    }

    long nextLong() throws IOException {
        return Long.parseLong(nextToken());
    }

    double nextDouble() throws IOException {
        return Double.parseDouble(nextToken());
    }

    class Edge {
        int e;
        Edge nt;
        Edge(int q, Edge w) {
            e = q; nt = w;
        }
    }

    Edge[] v;
    boolean[] w;
    int ta;

    int dfs(int q) {
        w[q] = true;
        int[] a = new int[202];
        int l = 0;
        for (Edge r = v[q]; r != null; r = r.nt) {
            if (!w[r.e]) {
                a[l++] = dfs(r.e);
            }
        }
        Arrays.sort(a, 0, l);
        if (l >= 2) {
            ta = Math.max(ta, a[l - 1] + a[l - 2] + 2);
        }
        if (l > 0) {
            ta = Math.max(ta, a[l - 1] + 1);
            return a[l - 1] + 1;
        } else return 0;
    }

    void addedge(int a, int b) {
        v[a] = new Edge(b, v[a]);
        v[b] = new Edge(a, v[b]);
    }

    void solve() throws Exception {
        int n = nextInt();
        int[] a = new int[n];
        int[] b = new int[n];
        for (int i = 0; i < n - 1; i++) {
            a[i] = nextInt();
            b[i] = nextInt();
        }
        int ans = 0;
        for (int rr = 0; rr < n - 1; rr++) {
            v = new Edge[n + 1];
            for (int i = 0; i < n - 1; i++) {
                if (i != rr) addedge(a[i], b[i]);
            }
            w = new boolean[n + 1];
            ta = 0;
            dfs(1);
            int res = ta;
            for (int i = 1; i <= n; i++) {
                if (!w[i]) {
                    ta = 0;
                    dfs(i);
                    res *= ta;
                    break;
                }
            }
            ans = Math.max(ans, res);
        }
        out.print(ans);
    }

    public void run() {
        try {
            Locale.setDefault(Locale.US);
            in = new BufferedReader(new InputStreamReader(System.in));
            out = new PrintWriter(System.out);
            solve();
        } catch (Exception e) {
            e.printStackTrace();
        }
        out.flush();
    }

}


import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner r = new Scanner(System.in);

		int n = r.nextInt();
		int[][] g = new int[n][n];

		for(int i = 0; i < n-1; i++){
			int f = r.nextInt()-1;
			int t = r.nextInt()-1;

			g[f][t] = g[t][f] = 1;
		}
		int max = 0;
		for(int f = 0; f < n; f++){
			for(int t = f+1; t < n; t++){
				if(g[f][t] == 1){
					g[f][t] = g[t][f] = 0;

					boolean[] v = new boolean[n];
					int[] res = new int[2];int p = 0;
					for(int i = 0; i < n; i++)if(!v[i]){
						v[i] = true;
						res[p++] = flood(i, g, v, n);
					}

					max = Math.max(max, res[0]*res[1]);

					g[f][t] = g[t][f] = 1;
				}
			}
		}

		System.out.println(max);
	}

	private static int flood(int i, int[][] g, boolean[] v, int n) {

		int res = 0;
		for(int j = 0; j < n; j++)if(g[i][j] == 1 && !v[j]){
			v[j] = true;
			res += 1 + flood(j, g, v, n);
		}
		return res;
	}
}


import java.util.Arrays;
import java.util.LinkedList;
import java.util.Queue;
import java.util.Scanner;

public class Main {
    static int[][] g;
    static int n;
    public static void main(String[] args) {
        Scanner r = new Scanner(System.in);

        n = r.nextInt();
        g = new int[n][n];

        for(int i = 0; i < n-1; i++){
            int f = r.nextInt()-1;
            int t = r.nextInt()-1;

            g[f][t] = g[t][f] = 1;
        }
        int max = 0;
        for(int f = 0; f < n; f++){
            for(int t = f+1; t < n; t++){
                if(g[f][t] == 1){

//                  System.out.println(f+" -- "+t);
                    g[f][t] = g[t][f] = 0;

                    int len1 = go(f);
                    int len2 = go(t);
//                  System.out.println(len1 + ", " + len2);

                    max = Math.max(max, len1*len2);

                    g[f][t] = g[t][f] = 1;
                }
            }
        }

        System.out.println(max);
    }

    private static int go(int f) {
        Queue<Integer> q = new LinkedList<Integer>();
        q.add(f);

        boolean[] v = new boolean[n];
        v[f] = true;
        int n1 = -1;
        while(!q.isEmpty()){
            n1 = q.poll();
//          System.out.println(n1);

            for(int j = 0; j < n; j++)if(g[n1][j] == 1 && !v[j]){
                v[j] = true;
                q.add(j);
            }
        }
//      if(f == 1)System.out.println(f + ", " + n1);

        Arrays.fill(v, false);
        int[] d = new int[n];
        q.add(n1);
        v[n1] = true;
        int n2 = -1;
        while(!q.isEmpty()){
            n2 = q.poll();

            for(int j = 0; j < n; j++)if(g[n2][j] == 1 && !v[j]){
                v[j] = true;
                d[j] = 1 + d[n2];
                q.add(j);
            }
        }

        return d[n2];
    }

    private static int getMax(int i, int[][] g, boolean[] v, int n) {
        int res = 0;
        v[i] = true;
        for(int j = 0; j < n; j++)if(g[i][j] == 1 && !v[j]){
            res = Math.max(res, 1+getMax(j, g, v, n));
        }
        v[i] = false;

        return res;
    }

    private static int flood(int i, int[][] g, boolean[] v, int n) {
        int res = 0;
        for(int j = 0; j < n; j++)if(g[i][j] == 1 && !v[j]){
            v[j] = true;
            res += 1 + flood(j, g, v, n);
        }
        return res;
    }
}


import java.util.ArrayList;
import java.util.Arrays;
import java.util.Scanner;

public class e_16 {
    static boolean[] visited;
    static ArrayList<Integer> list[];

    public static int dfs(int i) {
        visited[i] = true;
        int res = 0;
        for (int x : list[i])
            if (!visited[x])
                res = Math.max(res, 1 + dfs(x));
        return res;
    }

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        list = new ArrayList[n];
        visited = new boolean[n];
        edge[] edges = new edge[n - 1];
        for (int i = 0; i < n; i++)
            list[i] = new ArrayList<Integer>();
        for (int i = 0; i < n - 1; i++) {
            int a = in.nextInt() - 1;
            int b = in.nextInt() - 1;
            edge e = new edge(a, b);
            edges[i] = e;
            list[a].add(b);
            list[b].add(a);
        }
        int res = 0;
        visited = new boolean[n];
        for (int i = 0; i < n - 1; i++) {
            edge e = edges[i];
            int a = e.a;
            int b = e.b;
            Arrays.fill(visited, false);
            visited[b] = true;
            int x = 0;
            for (int z : list[a])
                if (!visited[z])
                    x += dfs(z);
            Arrays.fill(visited, false);
            visited[a] = true;
            int y = 0;
            for (int z : list[b])
                if (!visited[z])
                    y += dfs(z);
            // System.out.println((a+1)+" "+(b+1)+" "+x+" "+y);
            res = Math.max(res, x * y);
        }
        System.out.println(res);
    }

    static class edge {
        int a, b;

        public edge(int a, int b) {
            this.a = a;
            this.b = b;
        }
    }
}


import java.util.ArrayList;
import java.util.Arrays;
import java.util.Scanner;

public class d_14 {
	static ArrayList<Integer>[] list;
	static boolean[] visited;
	static int max, res;

	public static void dfs(int i, int len) {
		// System.out.println(i+" "+len);
		if (len > max) {
			max = len;
			res = i;
		}
		visited[i] = true;
		for (int x : list[i])
			if (!visited[x])
				dfs(x, len + 1);
	}

	public static int diameter(int i, int cut) {
		Arrays.fill(visited, false);
		visited[cut] = true;
		res = i;
		dfs(i, 0);
		max = 0;
		Arrays.fill(visited, false);
		visited[cut] = true;
		dfs(res, 0);
		return max;
	}

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		visited = new boolean[n];
		list = new ArrayList[n];
		for (int i = 0; i < n; i++)
			list[i] = new ArrayList<Integer>();
		edge[] edges = new edge[n - 1];
		for (int i = 0; i < n - 1; i++) {
			int a = in.nextInt() - 1;
			int b = in.nextInt() - 1;
			edges[i] = new edge(a, b);
			list[a].add(b);
			list[b].add(a);
		}
		// System.out.println(diameter(3,2 ));
		int re = 0;
		for (int i = 0; i < edges.length; i++) {
			max = res = 0;
			int a = edges[i].a;
			int b = edges[i].b;
			int temp1 = diameter(a, b);
			max = res = 0;
			int temp2 = diameter(b, a);
			// System.out.println((a+1)+" "+(b+1)+" "+temp1+" "+temp2);
			re = Math.max(re, temp1 * temp2);
		}
		System.out.println(re);
	}

	static class edge {
		int a, b;

		public edge(int a, int b) {
			this.a = a;
			this.b = b;
		}
	}
}


import java.util.Scanner;

public class D14 {

    static int n, max;
    static int[][] a;
    static int[] b;
    static boolean[] used;

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        n = sc.nextInt();
        a = new int[n+1][n+1];
        b = new int[n+1];
        for (int i = 1; i < n; i++) {
            int x = sc.nextInt();
            int y = sc.nextInt();
            a[x][y] = 1;
            a[y][x] = 1;
        }
        int ans = 0;
        for (int i = 1; i <= n; i++) {
            for (int j = 1; j <= n; j++) {
                if (a[i][j] == 1) {
                    used = new boolean[n+1];
                    used[j] = used[i] = true;
                    max = 0;
                    chuqir_kir(i);
                    int s1 = max;
                    max = 0;
                    chuqir_kir(j);
                    ans = Math.max(ans, max * s1);
                }
            }
        }
        System.out.println(ans);
    }

    private static void chuqir_kir(int v) {
        int max1 = 0;
        for (int i = 1; i <= n; i++) {
            if (a[v][i] == 1 && !used[i]) {
                used[i] = true;
                chuqir_kir(i);
                b[v] = Math.max(b[v], b[i] + 1);
                if (b[i] + 1 > max) {
                    max1 = max;
                    max = b[i] + 1;
                } else {
                    if (b[i] + 1 > max1)
                        max1 = b[i] + 1;
                }
            }
        }
        max += max1;
    }
}


import java.util.Scanner;

public class D14 {

    static int n, max;
    static int[][] a;
    static int[] b;
    static boolean[] used;

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        n = sc.nextInt();
        a = new int[n+1][n+1];
        for (int i = 1; i < n; i++) {
            int x = sc.nextInt();
            int y = sc.nextInt();
            a[x][y] = 1;
            a[y][x] = 1;
        }
        int ans = 0;
        for (int i = 1; i <= n; i++) {
            for (int j = 1; j <= n; j++) {
                if (a[i][j] == 1) {
                    b = new int[n+1];
                    used = new boolean[n+1];
                    used[j] = used[i] = true;
                    max = 0;
                    chuqir_kir(i);
                    int s1 = max;
                    max = 0;
                    used = new boolean[n+1];
                    used[j] = used[i] = true;
                    chuqir_kir(j);
                    ans = Math.max(ans, max * s1);
                }
            }
        }
        System.out.println(ans);
    }

    private static void chuqir_kir(int v) {
        int max1 = 0, max2 = 0;
        for (int i = 1; i <= n; i++) {
            if (a[v][i] == 1 && !used[i]) {
                used[i] = true;
                chuqir_kir(i);
                b[v] = Math.max(b[v], b[i] + 1);
                if (b[i] + 1 > max2) {
                    max1 = max2;
                    max2 = b[i] + 1;
                } else {
                    if (b[i] + 1 > max1)
                        max1 = b[i] + 1;
                }
            }
        }
        max = Math.max(max, max1+max2);
    }
}