//#include<bits/stdc++.h>
#include<vector>
#include<iostream>
#include<algorithm>
#define ll long long
#define ldb long double
#define fi first
#define se second
#define sza(a) (int)a.size()
#define pir pair<int,int>
#define pirll pair<ll,ll>
using namespace std;
const int maxn = 2e5 + 5;
template <typename T> void maxi(T &x,T y){if (x < y) x = y;}
struct tree{
int D[maxn],sz[maxn];
ll R[maxn],V[maxn][2],child_cost[maxn],dp[maxn],maxR = 0;
vector<int> vec[maxn];
void add_edge(int u,int v){
vec[u].push_back(v);
vec[v].push_back(u);
}
void init_dfs(int u,int par){
sz[u] = 1;
if (u == 1) D[u] = 1;
for (int v : vec[u])
if (v != par){
D[v] = D[u] + 1;
init_dfs(v,u);
sz[u] += sz[v];
}
}
ll calc_self_cost(int n){
ll cost = 0;
for (int u = 1 ; u <= n ; u++)
cost += (ll)sz[u] * (ll)(n - sz[u]);
return cost;
}
void child_cost_dfs(int u,int par){
for (int v : vec[u])
if (v != par){
child_cost_dfs(v,u);
child_cost[u] += child_cost[v] + sz[v];
}
}
void reroot_dfs(int u,int par,ll cur){
R[u] = child_cost[u] + cur;
maxi(maxR,R[u]);
for (int v : vec[u])
if (v != par) cur += child_cost[v] + sz[v];
for (int v : vec[u])
if (v != par)
reroot_dfs(v,u,cur - child_cost[v] - sz[v] + sz[1] - sz[v]);
}
void perform_reroot(int n){
//->R : reroot
child_cost_dfs(1,0);
reroot_dfs(1,0,0);
}
void middle_dfs(int u,int par,ll S,int n,int n1,int n3,ll R1,ll R3){
for (int v : vec[u])
if (v != par)
middle_dfs(v,u,S,n,n1,n3,R1,R3);
V[u][0] = (ll)D[u] * S + R[u] * (ll)n1;
V[u][1] = (ll)D[u] * S + R[u] * (ll)n3;
ll &f = dp[u];
f = V[u][0] + V[u][1];
for (int v : vec[u])if (v != par){
maxi(f,V[u][0] + V[v][1]);
maxi(f,V[u][1] + V[v][0]);
maxi(V[u][0],V[v][0]);
maxi(V[u][1],V[v][1]);
}
f -= 2*(ll)D[u] * S;
f += (ll)(n + n1) * (ll)n3 + (ll)(n + n3) * (ll)n1;
f += R3 * (ll)(n + n1);
f += R1 * (ll)(n + n3);
}
ll middle_cost(int n,int n1,int n3,ll R1,ll R3){
ll S = (ll)n1 * (ll)n3;
middle_dfs(1,0,S,n,n1,n3,R1,R3);
ll cost = 0;
for (int u = 1 ; u <= n ; u++)
maxi(cost,dp[u]);
return cost;
}
} tree[3];
int n[3];
void input_tree(){
for (int i = 0 ; i < 3 ; i++){
cin >> n[i];
for (int m = 1 ; m < n[i] ; m++){
int u,v;
cin >> u >> v;
tree[i].add_edge(u,v);
}
}
}
ll solve(){
ll res = 0;
int N = 3;
for (int id = 0 ; id < N ; id++){
tree[id].init_dfs(1,0);
res += tree[id].calc_self_cost(n[id]);
}
for (int id = 0 ; id < N ; id++)
tree[id].perform_reroot(n[id]);
ll tmp = 0;
for (int id = 0 ; id < N ; id++){
int i1 = (id + 1) % N,i2 = (id + 2) % N;
ll R1 = tree[i1].maxR,R2 = tree[i2].maxR;
tmp = max(tmp,tree[id].middle_cost(n[id],n[i1],n[i2],R1,R2)); //??additional cost)
}
res += tmp;
return res;
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);cout.tie(0);
freopen("3cay.inp","r",stdin);
freopen("3cay.out","w",stdout);
int stt;cin >> stt;
input_tree();
cout << solve();
return 0;
}
Ly8jaW5jbHVkZTxiaXRzL3N0ZGMrKy5oPgojaW5jbHVkZTx2ZWN0b3I+CiNpbmNsdWRlPGlvc3RyZWFtPgojaW5jbHVkZTxhbGdvcml0aG0+CiNkZWZpbmUgbGwgbG9uZyBsb25nCiNkZWZpbmUgbGRiIGxvbmcgZG91YmxlCiNkZWZpbmUgZmkgZmlyc3QKI2RlZmluZSBzZSBzZWNvbmQKI2RlZmluZSBzemEoYSkgKGludClhLnNpemUoKQojZGVmaW5lIHBpciBwYWlyPGludCxpbnQ+CiNkZWZpbmUgcGlybGwgcGFpcjxsbCxsbD4KdXNpbmcgbmFtZXNwYWNlIHN0ZDsKY29uc3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