#include <bits/stdc++.h>
#define endl '\n'
#define int long long
using namespace std;
typedef pair<int, int> PII;
const int N = 100010;
int n;
vector<int> h[N];
int d[N];
void topsort()
{
queue<int> q;
for (int i = 1; i <= n; i++)
{
d[i] = h[i].size();
if (d[i] == 1) q.push(i);
}
while (q.size())
{
auto t = q.front();
q.pop();
for (int i = 0; i < h[t].size(); i++)
{
int j = h[t][i];
d[j]--;
if (d[j] == 1) q.push(j);
}
}
}
signed main()
{
ios ::sync_with_stdio(0);
cin.tie(0);cout.tie(0);
cin >> n;
for (int i = 1; i <= n; i++)
{
int u, v;
cin >> u >> v;
h[u].push_back(v), h[v].push_back(u);
}
topsort();
int cnt = 0, m1 = 0, m2 = 0;
for (int i = 1; i <= n; i++)
{
if (d[i] > 1)
{
cnt++;
m1 = max(m1, (int)h[i].size());
}
else m2 = max(m2, (int)h[i].size());
}
if (m2 == 4) cout << cnt * (n - 1);
else if (maxv < 4) cout << cnt * n << endl;
else if (maxv == 4) cout << n * 2 + (cnt - 2) * (n - 1) << endl;
else cout << (n - 1) * 2 << endl;
return 0;
}