#include<bits/stdc++.h> #define ll long long #define INF 1e9 usingnamespace std; int m, n, k, ans; int fa[1000005]; intfind_root(int n){ // 查找根 if (fa[n] == n) return n; return fa[n] = find_root(fa[n]); } voidmerge(int x, int y){ // 合并 int sx = find_root(x), sy = find_root(y); if (sx != sy) fa[sx] = sy; } signedmain(){ ios :: sync_with_stdio(0); cin >> m >> n >> k; for (int i = 1; i <= m * n; i++) fa[i] = i; // 预处理 for (int i = 1; i <= k; i++) { int u, v; cin >> u >> v; merge(u, v); } for (int i = 1; i <= m * n; i++) { if (fa[i] == i) ans++; // 如果是根,答案增加 } cout << ans; return0; }