This is a creation in Article, where the information may have evolved or changed.
/* Update the flag as soon as the status is queued in the search
Can not be updated when the team, or some of the middle of the state will repeat the search caused errors. */
#include <stdio.h> #include <cstring> #include <queue> #include <iostream>using namespace std; int Map[21][21];bool vis[21][21];int dx[4]= {1,-1,0,0};int dy[4]= {0,0,-1,1};int cb,cw,n;struct point{int x, y;} p,t;void BFS (int x,int y) {p.x=x,p.y=y; Queue <point> q; Q.push (P); int num=0; Vis[p.x][p.y]=true; int r2=-1,r3=-1; while (!q.empty ()) {T=q.front (); num++; Q.pop (); for (int i=0; i<4; i++) {p.x=t.x+dx[i]; P.y=t.y+dy[i]; if (vis[p.x][p.y]) continue; if (p.x<1| | p.x>n| | p.y<1| | P.y>n) continue; if (map[p.x][p.y]==1) r2=1; else if (map[p.x][p.y]==2) r3=1; else Q.push (p), vis[p.x][p.y]=true; }} if (R2==1&&r3==1) return; if (r3==-1) cb+=num; else if (r2==-1) cw+=num; return;} int main () {int b,w,x,y; while (scanf ("%d", &n) ==1&&n) {memset (map,0,sizeof (map)); memset (vis,false,sizeof (VIS)); cb=cw=0; scanf ("%d%d", &b,&w); for (int i=0; i<b; i++) scanf ("%d%d", &x,&y), map[x][y]=1; for (int i=0; i<w; i++) scanf ("%d%d", &x,&y), map[x][y]=2; for (int i=1, i<=n; i++) for (int j=1; j<=n; J + +) if (!map[i][j]&&!vis[i][j]) BFS (i,j ); if (CB==CW) printf ("draw\n"); else if (CB>CW) printf ("Black wins by%d\n", CB-CW); else printf ("White wins by%d\n", CW-CB); } return 0;}