题目链接:http://acm.tju.edu.cn/toj/showp4014.html
int n, m, flg = 0, ans; int h[105][105], v[105][105]; vint g[maxn]; bool vis[maxn]; void add(int u, int v) { g[u].puck(v); g[v].puck(u); } void dfs(int u) { flg++; vis[u] = 1; inc(i, 0, g[u].size()) { if(!vis[g[u][i]]) dfs(g[u][i]); } } void solve() { ans = 0; inc(i, 1, n + m + 1) { if(!vis[i]) { flg = 0; dfs(i); ans += (flg + 1)>>1; } } } int main() { while(~cii(n, m), n + m) { mem(vis); mem(h);mem(v); inc(i, 0, n + m + 1) g[i].clear(); itn x, y; inc(i, 1, n + 1) { cii(x, y); h[x][y] = h[x + 1][y] = i; } inc(i, n + 1, n + m + 1) { cii(x, y); v[x][y] = v[x][y + 1] = i; if(h[x][y] > 0) add(i, h[x][y]); if(h[x][y + 1] > 0) add(i, h[x][y + 1]); } solve(); ptt(ans); } }