BZOJ_2303_[APIO2011] Checkers Dyeing _ and check set

Source: Internet
Author: User

BZOJ_2303_[APIO2011] Checkers Dyeing _ and check set

Description

Sam and his sister, Sara, have a nxm with a square.
Form. They want to dye each of their squares red or blue.
For personal preference, they want each 2x2 square area in the table
Fields contain an odd number (one or 3) of red squares. For example, right
Figure is a valid table dyeing scheme (in the printed version, the Dark generation
The table is blue and the light color represents red).
But last night, some of the squares in the table have been stained with color! Now Sam and Sara
Very angry. However, they want to know if it is possible to color the remaining squares so that the entire table
Still meet their demands. If possible, what are the number of staining schemes that meet their requirements?


Input

The first line of the input contains three integers n, m, and K, representing the number of rows, columns, and dyes of the table, respectively
The number of colored squares.
The following K-line describes the squares that have been stained. Where line I contains three integers xi, Yi and CI, respectively
Represents the row number, column number, and color of the square I have been stained. CI 1 means the squares are dyed red.
Color, CI 0 means that the squares are dyed blue.

Output

Outputs an integer that represents the number of possible staining schemes W-mode 10^9 the resulting value. (That is, if w is greater than or equal to 10^9, the output W is 10^9 in addition to the remainder).

For all the test data, 2≤n, m≤106
, 0≤k≤10^6
, 1≤xi≤n,1≤yi≤m.

Sample Input3 4 3
2 2 1
1 2 0
2 3 1
Sample Output8 for (I,J) there are a[i][j]^a[i+1][j]^a[i][j+1]^a[i+1][j+1]=1The formula from (i-1,j-1) is all different or up. get a[1][1]^a[1][j]^a[i][1]^a[i][j]=[i%2==0&&j%2==0]. The color of the first row and the first column determines the color of the entire square. so the color of the enumeration (X,Y,C), for each (the), the a[1][y] and a[x][1] and the collection connected together. There is no solution to the ring, otherwise the answer equals two of the number of connected blocks-1 times. Code:
#include <stdio.h> #include <string.h> #include <algorithm>using namespace std;typedef long Long ll;#    Define N 2000050inline char NC () {static Char buf[100000],*p1,*p2; Return p1==p2&& (p2= (p1=buf) +fread (Buf,1,100000,stdin), P1==P2)? eof:*p1++;}    inline Int Rd () {Register int x=0;    Register char S=NC (); while (s< ' 0 ' | |    S> ' 9 ') s=nc ();    while (s>= ' 0 ' &&s<= ' 9 ') x= (x<<3) + (x<<1) +s-' 0 ', s=nc (); return x;} int Fa[n],n,m,a[n],k,xx[n],yy[n],cc[n];ll Mod=1000000000;ll QP (ll X,ll y) {ll re=1; for (; y;y>>=1ll,x=x*x%mod) if ( Y&AMP;1LL) Re=re*x%mod; return re;}    int find (int x) {if (fa[x]==x) return x;    int Tmp=find (fa[x]);    A[X]^=A[FA[X]]; return fa[x]=tmp;}    int main () {n=rd (); M=rd (); K=rd ();    register int i;    for (i=1;i<=k;i++) {xx[i]=rd (); Yy[i]=rd (); Cc[i]=rd ();    } int col1,flg[2];    flg[0]=flg[1]=0;    ll Ans=0;        for (col1=0;col1<2;col1++) {int cnt=0; for (i=1;i<=n+m-1;i++) Fa[i]=i,a[i]=0;            for (i=1;i<=k;i++) {int p=col1^cc[i]^ (xx[i]%2==0&&yy[i]%2==0);            int x=xx[i],y=yy[i]+n-1;            int Dx=find (x), Dy=find (y);                if (dx!=dy) {fa[dx]=dy;            A[dx]=a[y]^a[x]^p;                }else {if ((A[x]^a[y])!=p) {flg[col1]=1; break;            }}} for (i=1;i<=n+m-1;i++) {if (fa[i]==i) {cnt++;        }} cnt--;        if (!flg[col1]) {ans= (ANS+QP (2,cnt))%mod; }} printf ("%lld\n", ans);}

BZOJ_2303_[APIO2011] Checkers Dyeing _ and check set

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.