#include #include #include struct Point { int x, y; Point(int x = 0, int y = 0): x(x), y(y) {} }; typedef std::queue< Point > Queue; static const int MAXN = 1024; int n, m, k; char a[MAXN][MAXN]; Queue q; void try_put(int x, int y) { if(x < 0 || y < 0 || x >= n || y >= m || a[y][x] != 0) return; a[y][x] = 1; q.push(Point(x,y)); } void fill(int x, int y) { try_put(x, y); while(!q.empty()) { Point p = q.front(); q.pop(); try_put(p.x - 1, p.y); try_put(p.x + 1, p.y); try_put(p.x, p.y - 1); try_put(p.x, p.y + 1); } } int main() { scanf("%d %d %d", &n, &m, &k); memset(a, 0, sizeof(a)); for(int i = 0; i < k; ++ i) { int x, y; scanf("%d %d", &x, &y); a[y - 1][x - 1] = -1; } int count = 0; for( int y = 0; y < m; ++ y ) for( int x = 0; x < n; ++ x ) if( a[y][x] ==0 ) fill(x, y), ++ count; printf("%d", count); return 0; }