// Sonny's solution to go // Stanford Local Programming Contest, October 2007 #include using namespace std; const int limit = 204; char board[limit][limit]; const int dx[4] = {0, -1, 1, 0}; const int dy[4] = {-1, 0, 0, 1}; bool seeb, seew; // evil recursive depth-first search! ;-) int search(int x, int y, int total) { board[x][y] = '.'; ++total; for (int i = 0; i < 4; ++i) { int nx = x+dx[i], ny = y+dy[i]; if (board[nx][ny]) { switch (board[nx][ny]) { case 'b': seeb = true; break; case 'w': seew = true; break; default: break; } } else total = search(nx, ny, total); } return total; } int main() { int n; while (cin >> n) { if (n == 0) break; // clear and pad the board memset(board, 0, limit*limit*sizeof(char)); for (int i = 0; i < n+2; ++i) { board[i][0] = board[i][n+1] = 'x'; board[0][i] = board[n+1][i] = 'x'; } int b, w, x, y; cin >> b >> w; for (int i = 0; i < b; ++i) { cin >> x >> y; board[x][y] = 'b'; } for (int i = 0; i < w; ++i) { cin >> x >> y; board[x][y] = 'w'; } // loop through the board and search unoccupied areas int black = 0, white = 0; for (int i = 1; i <= n; ++i) for (int j = 1; j <= n; ++j) if (board[i][j] == 0) { seeb = seew = false; int sum = search(i, j, 0); if (seeb && !seew) black += sum; else if (seew && !seeb) white += sum; } // print result if (black > white) cout << "Black wins by " << black-white << endl; else if (white > black) cout << "White wins by " << white-black << endl; else cout << "Draw" << endl; } return 0; }