#include #include #include using namespace std; typedef vector VI; typedef vector VVI; enum SQUARE { EMPTY, BLACK, WHITE, FILLED }; const int dr[] = {0, 1, 0, -1}; const int dc[] = {1, 0, -1, 0}; int FloodFill(VVI &board, int r, int c, bool &touches_white, bool &touches_black) { const int n = int(board.size()); int area = 0; queue > Q; Q.push(make_pair(r,c)); while (!Q.empty()) { r = Q.front().first; c = Q.front().second; Q.pop(); if (board[r][c] != EMPTY) continue; ++area; board[r][c] = FILLED; // look in four cardinal directions for (int d = 0; d < 4; d++) { int nr = r + dr[d]; int nc = c + dc[d]; if (nr >= 0 && nc >= 0 && nr < n && nc < n) { switch (board[nr][nc]) { case EMPTY: Q.push(make_pair(nr,nc)); break; case WHITE: touches_white = true; break; case BLACK: touches_black = true; break; } } } } return area; } void Process(VVI &board) { const int n = int(board.size()); int black = 0, white = 0; // check each unfilled lattice point for (int r = 0; r < n; r++) { for (int c = 0; c < n; c++) { bool touches_white = false; bool touches_black = false; int area = FloodFill(board, r, c, touches_white, touches_black); if (touches_white && !touches_black) white += area; if (touches_black && !touches_white) black += area; } } // print results if (white > black) { cout << "White wins by " << white - black << endl; } else if (black > white) { cout << "Black wins by " << black - white << endl; } else { cout << "Draw" << endl; } } int main() { int n, b, w, r, c; while (1) { cin >> n; if (n == 0) break; VVI board(n,VI(n,EMPTY)); cin >> b >> w; for (int i = 0; i < b; i++) { cin >> r >> c; board[r-1][c-1] = BLACK; } for (int i = 0; i < w; i++) { cin >> r >> c; board[r-1][c-1] = WHITE; } Process(board); } }