using System;
using System.Collections.Generic;
using System.Linq;
class Program
{
static string InputPattern = "InputX";
static List<string> GetInputList()
{
var WillReturn = new List<string>();
if (InputPattern == "Input1") {
WillReturn.Add("5");
WillReturn.Add("1 2");
WillReturn.Add("1 3");
WillReturn.Add("1 4");
WillReturn.Add("4 5");
//2
}
else if (InputPattern == "Input2") {
WillReturn.Add("7");
WillReturn.Add("3 1");
WillReturn.Add("1 2");
WillReturn.Add("6 3");
WillReturn.Add("2 4");
WillReturn.Add("7 3");
WillReturn.Add("2 5");
//4
}
else {
string wkStr;
while ((wkStr = Console.ReadLine()) != null) WillReturn.Add(wkStr);
}
return WillReturn;
}
static long[] GetSplitArr(string pStr)
{
return (pStr == "" ? new string[0] : pStr.Split(' ')).Select(pX => long.Parse(pX)).ToArray();
}
// 隣接リスト
static Dictionary<long, List<long>> mToNodeListDict = new Dictionary<long, List<long>>();
static void Main()
{
List<string> InputList = GetInputList();
long NodeCnt = long.Parse(InputList[0]);
long[] wkArr = { };
Action<string> SplitAct = (pStr) => wkArr = GetSplitArr(pStr);
foreach (string EachStr in InputList.Skip(1)) {
SplitAct(EachStr);
long FromNode = wkArr[0];
long ToNode = wkArr[1];
if (mToNodeListDict.ContainsKey(FromNode) == false) {
mToNodeListDict[FromNode] = new List<long>();
}
if (mToNodeListDict.ContainsKey(ToNode) == false) {
mToNodeListDict[ToNode] = new List<long>();
}
mToNodeListDict[FromNode].Add(ToNode);
mToNodeListDict[ToNode].Add(FromNode);
}
long Diameter, Leaf1, Leaf2;
List<long> CenterNodeList;
ClassTreeDiameter.DeriveTreeDiameter(1, mToNodeListDict,
out Diameter, out Leaf1, out Leaf2, out CenterNodeList);
// 木の中心が1ノードの場合
if (CenterNodeList.Count == 1) {
List<JyoutaiDef> ResultList = ExecDFS(CenterNodeList[0]);
long MaxLevel = ResultList.Max(pX => pX.Level);
ResultList.RemoveAll(pX => pX.Level < MaxLevel);
long TotalNodeCnt = 0;
var CntDict = new Dictionary<long, long>();
foreach (JyoutaiDef EachJyoutai in ResultList) {
if (CntDict.ContainsKey(EachJyoutai.Node_Level2) == false) {
CntDict[EachJyoutai.Node_Level2] = 0;
}
CntDict[EachJyoutai.Node_Level2]++;
TotalNodeCnt++;
}
long Answer = 0;
foreach (var EachCnt in CntDict.Values) {
long RestCnt = TotalNodeCnt - EachCnt;
Answer += EachCnt * RestCnt;
}
Console.WriteLine(Answer / 2);
}
else {
// 木の中心が2ノードの場合
List<JyoutaiDef> ResultList0 = ExecDFS(CenterNodeList[0]);
long MaxLevel0 = ResultList0.Max(pX => pX.Level);
ResultList0.RemoveAll(pX => pX.Level < MaxLevel0);
List<JyoutaiDef> ResultList1 = ExecDFS(CenterNodeList[1]);
long MaxLevel1 = ResultList1.Max(pX => pX.Level);
ResultList1.RemoveAll(pX => pX.Level < MaxLevel1);
Console.WriteLine(ResultList0.Count * ResultList1.Count);
}
}
static List<JyoutaiDef> ExecDFS(long pRootNode)
{
var ResultList = new List<JyoutaiDef>();
var Stk = new Stack<JyoutaiDef>();
JyoutaiDef WillPush;
WillPush.CurrNode = pRootNode;
WillPush.Node_Level2 = -1;
WillPush.Level = 1;
Stk.Push(WillPush);
var VisitedSet = new HashSet<long>();
VisitedSet.Add(pRootNode);
while (Stk.Count > 0) {
JyoutaiDef Popped = Stk.Pop();
ResultList.Add(Popped);
foreach (long EachToNode in mToNodeListDict[Popped.CurrNode]) {
if (VisitedSet.Add(EachToNode)) {
WillPush.CurrNode = EachToNode;
WillPush.Level = Popped.Level + 1;
if (WillPush.Level == 2) {
WillPush.Node_Level2 = EachToNode;
}
else {
WillPush.Node_Level2 = Popped.Node_Level2;
}
Stk.Push(WillPush);
}
}
}
return ResultList;
}
struct JyoutaiDef
{
internal long CurrNode;
internal long Node_Level2;
internal long Level;
}
}
#region ClassTreeDiameter
// 根付き木の直径を求めるクラス
internal class ClassTreeDiameter
{
// {ルートノード,連結リスト}を引数とし、
// {木の直径、葉ノード1、葉ノード2、木の中心のノードのList}を設定
static internal void DeriveTreeDiameter(
long pRootNode, Dictionary<long, List<long>> pToNodeListDict,
out long pDiameter, out long pLeaf1, out long pLeaf2,
out List<long> pCenterNodeList)
{
// ===============================================================
// double sweepのアルゴリズム
// ===============================================================
// 根ノードからの距離[ノード]なDict
var DistanceDictRoot = ExecDFS(1, pToNodeListDict);
pLeaf1 = DistanceDictRoot.OrderByDescending(pX => pX.Value).First().Key;
// 葉ノード1からの距離[ノード]なDict
var DistanceDictLeaf1 = ExecDFS(pLeaf1, pToNodeListDict);
pLeaf2 = DistanceDictLeaf1.OrderByDescending(pX => pX.Value).First().Key;
pDiameter = DistanceDictLeaf1.Values.Max();
pCenterNodeList = new List<long>();
// 葉ノード2からの距離[ノード]なDict
var DistanceDictLeaf2 = ExecDFS(pLeaf2, pToNodeListDict);
var OKDistanceSet = new HashSet<long>();
OKDistanceSet.Add(pDiameter / 2);
if (pDiameter % 2 == 1) {
OKDistanceSet.Add(pDiameter / 2 + 1);
}
var CenterNodeSet1 = new HashSet<long>();
foreach (var EachPair in DistanceDictLeaf1) {
if (OKDistanceSet.Contains(EachPair.Value)) {
CenterNodeSet1.Add(EachPair.Key);
}
}
var CenterNodeSet2 = new HashSet<long>();
foreach (var EachPair in DistanceDictLeaf2) {
if (OKDistanceSet.Contains(EachPair.Value)) {
CenterNodeSet2.Add(EachPair.Key);
}
}
CenterNodeSet1.IntersectWith(CenterNodeSet2);
pCenterNodeList.AddRange(CenterNodeSet1);
}
// 根ノードを引数としてDFSを行う
static private Dictionary<long, long> ExecDFS(long pRootNode, Dictionary<long, List<long>> pToNodeListDict)
{
var DistanceDict = new Dictionary<long, long>();
var Stk = new Stack<JyoutaiDefTreeDiameter>();
JyoutaiDefTreeDiameter WillPush;
WillPush.CurrNode = pRootNode;
WillPush.Distance = 0; // 距離なので0始まり
Stk.Push(WillPush);
var VisitedSet = new HashSet<long>();
VisitedSet.Add(pRootNode);
while (Stk.Count > 0) {
JyoutaiDefTreeDiameter Popped = Stk.Pop();
DistanceDict[Popped.CurrNode] = Popped.Distance;
foreach (long EachToNode in pToNodeListDict[Popped.CurrNode]) {
if (VisitedSet.Add(EachToNode)) {
WillPush.CurrNode = EachToNode;
WillPush.Distance = Popped.Distance + 1;
Stk.Push(WillPush);
}
}
}
return DistanceDict;
}
private struct JyoutaiDefTreeDiameter
{
internal long CurrNode;
internal long Distance;
}
}
#endregion