#define _USE_MATH_DEFINES #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include//assert(); //#include //xAOJ ///////// #define REP(i, x, n) for(int i = x; i < n; i++) #define rep(i,n) REP(i,0,n) #define P(p) cout<<(p)< ///////// typedef long long LL; typedef long double LD; typedef unsigned long long ULL; ///////// using namespace::std; ///////// ///////// void solve(){ int H,W; cin >> H >> W; vector< vector > masu(H,vector(W) ); int temp; for(int h=0;h> temp; if( temp == 0 ){ masu[h][w] = false; }else{ masu[h][w] = true; } } } //////////////// int Q; cin >> Q; pair qtemp,inqueue; int X; bool bX; queue< pair > q; int dx[4] = {1,0,-1,0}; int dy[4] = {0,1, 0,-1}; int k; while(Q--){ cin >> qtemp.first >> qtemp.second >> X; --qtemp.first; --qtemp.second; bX = X==0?false:true; if( masu[qtemp.first][qtemp.second] == bX )continue; masu[qtemp.first][qtemp.second] = bX; q.push( qtemp ); while( !q.empty() ){ qtemp = q.front(); q.pop(); //masu[btemp.first][btemp.second] = X;//X以外の連結をXに塗る for(k=0;k<4;++k){ inqueue.first = qtemp.first + dx[k]; inqueue.second = qtemp.second + dy[k]; if( 0 <= inqueue.first && inqueue.first < H && 0 <= inqueue.second && inqueue.second < W ){ if( masu[inqueue.first][inqueue.second] != bX ){ masu[inqueue.first][inqueue.second] = bX; q.push( inqueue ); } } } } } for(int h=0;h