#include using namespace std; #define rep(i, n) for(int(i) = 0; (i) < (n); (i)++) #define FOR(i, m, n) for(int(i) = (m); (i) < (n); (i)++) #define All(v) (v).begin(), (v).end() #define pb push_back #define MP(a, b) make_pair((a), (b)) template vector make_vec(size_t a, T val) { return vector(a, val); } template auto make_vec(size_t a, Ts... ts) { return vector(a, make_vec(ts...)); } using ll = long long; using pii = pair; using pll = pair; using Graph = vector>; template struct edge { int to; T cost; edge(int t, T c) : to(t), cost(c) {} }; template using WGraph = vector>>; const int INF = 1 << 30; const ll LINF = 1LL << 60; const int MOD = 1e9 + 7; // UnionFind struct UnionFind { vector par; vector siz; UnionFind(ll N) : par(N), siz(N, 1LL) { for(int i = 0; i < N; i++) par[i] = i; } int root(int x) { if(par[x] == x) return x; return par[x] = root(par[x]); } void unite(int x, int y) { int rx = root(x); int ry = root(y); if(rx == ry) return; if(siz[rx] < siz[ry]) swap(rx, ry); siz[rx] += siz[ry]; par[ry] = rx; } bool same(int x, int y) { int rx = root(x); int ry = root(y); return rx == ry; } ll size(ll x) { return siz[root(x)]; } }; void dfs(int v, const Graph &G, set &se) { for(auto nv : G[v]) { if(se.count(nv)) continue; se.insert(nv); dfs(nv, G, se); } } int main() { int N, D, W; cin >> N >> D >> W; UnionFind uf(N); rep(i, D) { int a, b; cin >> a >> b; a--, b--; uf.unite(a, b); } Graph G(N); rep(i, W) { int c, d; cin >> c >> d; c--, d--; G[c].pb(d); G[d].pb(c); } map> mp; rep(i, N) { mp[uf.root(i)].pb(i); } ll res = 0; for(auto [root, list] : mp) { ll fst = list.size(); set se; for(auto v : list) { se.insert(v); dfs(v, G, se); } ll sec = se.size(); res += fst * (sec - 1); } cout << res << endl; }