#include <bits/stdc++.h>
using namespace std;
vector<int> adj[100001];
vector<pair<int, int> > e;
bool visit[100001];
long long e1, e2;
long long n, x, y;
long long d[100001];
long long bfs(long long start, long long state) {
  queue<int> q;
  q.push(start);
  memset(visit, false, sizeof(visit));
  memset(d, 0, sizeof(d));
  visit[start] = true;
  while (!q.empty()) {
    long long fr = q.front();
    q.pop();
    for (int i = 0; i < adj[fr].size(); i++) {
      if (!visit[adj[fr][i]] && !(e1 == fr && e2 == adj[fr][i]) &&
          !(e1 == adj[fr][i] && e2 == fr)) {
        q.push(adj[fr][i]);
        visit[adj[fr][i]] = true;
        d[adj[fr][i]] = d[fr] + 1;
      }
    }
  }
  long long node = 0;
  long long max_dist = 0;
  for (int i = 1; i <= n; i++) {
    if (d[i] > max_dist) {
      max_dist = d[i];
      node = i;
    }
  }
  if (state == 1)
    return max_dist;
  else {
    return bfs(node, 1);
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin >> n;
  for (int i = 0; i < n - 1; i++) {
    cin >> x >> y;
    adj[x].push_back(y);
    adj[y].push_back(x);
    e.push_back(make_pair(x, y));
  }
  long long max_ans = 0, path1 = 0, path2 = 0;
  for (int i = 0; i < n - 1; i++) {
    e1 = e[i].first;
    e2 = e[i].second;
    path1 = bfs(e1, 0);
    path2 = bfs(e2, 0);
    max_ans = max(max_ans, path1 * path2);
  }
  cout << max_ans << endl;
}
