Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstdlib>
- using namespace std;
- int quick_power (int a, int n)
- {
- int r=1;
- while (n>0)
- {
- if (n%2==1)
- {
- r*=a;
- n--;
- }
- a*=a;
- n/=2;
- }
- return r;
- }
- int main()
- {
- int n,m,c,i,j,x1,x2,xm,s,d,ch,ch1=0;
- cin >> n >> m;
- int a[2*n][2*n], b[n];
- for (i=0;i<2*n;i++)
- {
- for (j=0;j<2*n;j++)
- {
- a[i][j]=0;
- }
- }
- for (j=0;j<n;j++)
- {
- b[j]=quick_power(2,j);
- }
- s=quick_power(2,n);
- for (i=0;i<m;i++)
- {
- cin >> x1 >> x2;
- xm=min(x1,x2);
- x1=max(x1,x2);
- if (xm<0)
- xm=xm+n;
- else
- xm=xm+n-1;
- if (x1<0)
- x1=x1+n;
- else
- x1=x1+n-1;
- a[xm][x1]=1;
- }
- for (i=0;i<s;i++)
- {
- ch=0;
- for (c=0;c<2*n;c++)
- {
- if (ch==0)
- {
- for (d=c;d<2*n;d++)
- {
- if (d+c!=2*n-1 && a[c][d]==1)
- {
- if (c<n)
- {
- x1=(i/b[n-c-1]+1)%2;
- }
- else
- {
- x1=(i/b[c-n])%2;
- }
- if (d<n)
- {
- x2=(i/b[n-d-1]+1)%2;
- }
- else
- {
- x2=(i/b[d-n])%2;
- }
- if (x1==0 && x2==0)
- {
- ch=1;
- break;
- }
- }
- }
- }
- }
- if (c==2*n && d==2*n)
- {
- ch1=1;
- break;
- }
- }
- if (ch1==1)
- cout << "NO" << endl;
- else
- cout << "YES" << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement