bzoj4466 Super Cube

Source: Internet
Author: User

Description

Hypercube is the extension of a cube in a high-dimensional space (it degrades to a square in 2-D, 1
degenerate into segments in the case of dimensions). In the field of theoretical computer science, hypercube can often be used with 2 binary
coded together. The will nature of research on theoretical computer Science also has
own thinking.

is the graph of the hypercube in the 0~4 dimension space. Obviously we can put the hypercube
each vertex of the body is regarded as a point, and each edge is viewed as a side, so that a graph is given, and I
They call it a hypercube chart.
the hypercube map in D-dimensional space has 2D dots, and we numbered the points from 0 to 2d-1.
There is an interesting and important conclusion: there must be a numbering method that makes any
There is exactly one difference between the numbered 2 codes of the two vertices that have edges connected to each other.
in 2 and 3 dimensional space This conclusion can be such an image of understanding:
for 2-dimensional space, we just put this square in the first quadrant, making the 4 vertices sit
The mark is in counter-clockwise order (0,0), (1,0), ((), (0,1), and then the coordinates as 2-bit 2-binary
number, then the 4 points are numbered 0,1,3,2.
for 3-dimensional space, we can also overlap one vertex of a cube with the origin and make all
The edges are parallel to the axes, then the coordinates of the 8 points are determined, and finally the coordinates in the 3-dimensional space are viewed
into a 3-bit 2 binary number. For d-dimensional spaces, and so on.
now for an N-1 graph of N-point m-bars (numbered from 0 to--) for each point, will wants to
know if this diagram is isomorphic to a hypercube diagram.

Input

The first line contains an integer q indicating that this data contains a total of Q queries.
Next, the Q group asks, the input format for each group of queries is as follows:
The first line consists of two integers N and M,
Next M line, 2 different integer x, y for each line, indicates that there is a non-forward join in the graph
Points for X and y (0 < = x, y < N)
q<=3,n<=32768,m<=1000000

Output

For each query, output one line, the following:
1, if the query given in the diagram is different in any one hypercube, output-1;
2, if isomorphic to a certain hypercube diagram, then please renumber these n points in the graph, and in this
A row outputs N spaces separated by a space, representing the new number of each point in the original image, making renumbering
To meet the conclusions described in the topic.
Note: Each line of the output file either contains only an integer-1, or it should contain a 0
To N-1 this N number of permutations. If there is more than one set of solutions to the output of either.

A hypercube diagram satisfies:

1. Each vertex has the same degree of K

2. A total of 2k vertices, k2k-1 bar edge

3. After marking any side of the two-end label binary means that only 1-bit difference

4. The label of all points adjacent to each point is different from the bits of this dot label

Not in accordance with 1.2. Direct output-1, in accordance with 1.2. The BFS can be labeled first and verify that the label is valid (the label is not repeated and complies with 3.4.)

BFS, either take a point designator 0, its adjacent point label is a power of 2, take the non-marking and the point adjacent to the labeled Point, marking it as the label of the adjacent labeled point of the bitwise OR value

#include <cstdio>inlineintinput () {intx=0, c=GetChar ();  while(c> $|| c< -) c=GetChar ();  while(c> -&&c< -) x=x*Ten+c- -, c=GetChar (); returnx;}Const intn=32768;intId[n],rs[n],ed[n];inte[ -][n],p[n],dc[n+1];intQ[n],ql=0, qr=0;intn,m,a,b;voidchk () {n=input (); M=input (); BOOLun=0; QL=qr=0; intD=Dc[n]; if(n==1&&m==0) {puts ("0"); return; }    if(! d| | m*2!=N*D) un=1; if(!un) for(intI=0; i<n;i++) p[i]=ed[i]=id[i]=rs[i]=0;  while(m--) {a=input (), b=input (); if(p[a]>=d| | P[b]>=d) un=1; if(un)Continue; E[p[a]++][a]=b; E[P[B]++][b]=A; } ed[0]=1; if(!un) for(intI=0; i<p[0];i++){        intw=e[i][0]; if(Ed[w]) {un=1; Break;} ED[W]=1; Q[QR++]=W; ID[W]=1<<i; }    if(!un) while(ql<qr) {        intw=q[ql++]; ED[W]=1;  for(intI=0; i<p[w];i++){            intu=E[i][w]; if(ed[u]==1)Continue; Id[u]|=Id[w]; if(!Ed[u]) {Ed[u]=2; Q[QR++]=u; }        }    }    if(!un) for(intI=0; i<n;i++){        if(Rs[id[i]]) {un=1; Break;} Rs[id[i]]=i; }    if(!un) for(intI=0; i<n&&!un;i++){        ints=0;  for(intj=0; j<p[i];j++){            intu=E[j][i]; intc=id[u]^Id[i]; if(s&c) {un=1; Break;} if(c!= (C&AMP;-C)) {un=1; Break;} S|=C; }        if(s+1!=n) un=1; }    if(un) puts ("-1"); Else{printf ("%d", id[0]);  for(intI=1; i<n;i++) printf ("%d", Id[i]); Putchar (Ten); }}intMain () { for(intI=0;i< -; i++) dc[1<<i]=i; intt=input ();  while(t--) chk (); return 0;}

bzoj4466 Super Cube

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.