Machines on the Moon

아직 제출이 없습니다시간 제한12초메모리 제한256 MB

문제

Jeff is an inventor. Throughout his life, he invented various machines. He never gets patents for them because he has never trusted the government.

A machine of order \ell is an acyclic directed graph with \ell sources (vertices with no incoming edges) and one selected sink (vertex with no outgoing edges). Each vertex of the graph except sources has exactly two inner edges. One inner edge is referred to as the left edge, and another one is referred to as the right edge.

Each vertex vv of the graph computes a function f_v:0,10,1f\_v: \\{0, 1\\}^\ell \to \\{0, 1\\}. In particular, ii-th source s_is\_i computes the function f_s_i(x_1,,x_n)=x_if\_{s\_i}(x\_1, \ldots, x\_n) = x\_i. Each inner vertex vv is labeled with the function b_v:0,120,1b\_v: \\{0, 1\\}^2 \to \\{0, 1\\}. Let uu be the starting vertex of the left inner edge to vv, and ww be the starting vertex of the right inner edge. The function f_vf\_v is then defined as f_v(x)=b(f_u(x),f_w(x)).f\_v(x) = b(f\_u(x), f\_w(x))\text{.} Jeff says that the function computed by a machine is the function computed by its selected sink.

One problem keeps Jeff awake at night for a couple of months. Jeff has an undirected graph G=(V,E)G = (V, E) which his uncle John left him. Jeff is really puzzled with cliques and independent sets in this graph.

A set SVS \subseteq V is a clique of the graph G=(V,E)G = (V, E) if, for every pair of distinct vertices u,vSu, v \in S, we have (u,v)E(u, v) \in E.

A set SVS \subseteq V is an independent set of the graph G=(V,E)G = (V, E) if, for every pair of distinct vertices u,vSu, v \in S, we have (u,v)∉E(u, v) \not\in E.

Jeff has noticed that if II is an independent set and CC is a clique, then IC1|I \cap C| \le 1. But it still leaves two options: either IC=I \cap C = \varnothing or IC=1|I \cap C| = 1.

Let n=Vn = |V|. Jeff denotes a vector corresponding to the set SS as χ_S0,1n\chi\_S \in \\{0, 1\\}^n: the ii-th component of χ_S\chi\_S is 11 if iSi \in S and 00 otherwise.

Jeff wants to build two machines of order n+2kn + 2k, where n=Vn = |V| and kk is Jeff's favorite positive integer, such that they would be able to decide if IC=I \cap C = \varnothing together.

The first machine receives a vector χ_C0,1n\chi\_C \in \\{0, 1\\}^n, where CC is a clique, followed by 2k2k zeroes. The second machine receives a vector χ_I0,1n\chi\_I \in \\{0, 1\\}^n, where II is an independent set, followed by 2k2k zeroes. After that, the machines will work together using the scheme described below and decide if IC=I \cap C = \varnothing.

Let us denote the first machine as AA and identify it with the function it computes. For example, we denote the result of the first execution as A(χ_C,0,,0_2k)0,1A(\chi\_C, \underbrace{0, \ldots, 0}\_{2k}) \in \\{0, 1\\}. Similarly, we denote the second machine as BB.

Jeff has developed a scheme to make the machines work together. Let a_0=A(χ_C,0,,0_2k),a\_0 = A(\chi\_C, \underbrace{0, \ldots, 0}\_{2k})\text{,} b_0=B(χ_I,0,,0_2k).b\_0 = B(\chi\_I, \underbrace{0, \ldots, 0}\_{2k})\text{.}

Then let a_i=A(χ_C,a_0,b_0,a_1,b_1,a_i1,b_i1,1,0,,0_2(ki1)1),a\_i = A(\chi\_C, a\_0, b\_0, a\_1, b\_1 \ldots, a\_{i-1}, b\_{i-1}, 1, \underbrace{0, \ldots, 0}\_{2(k-i-1) - 1})\text{,} b_i=B(χ_I,a_0,b_0,a_1,b_1,a_i1,b_i1,1,0,,0_2(ki1)1).b\_i = B(\chi\_I, a\_0, b\_0, a\_1, b\_1 \ldots, a\_{i-1}, b\_{i-1}, 1, \underbrace{0, \ldots, 0}\_{2(k-i-1) - 1})\text{.}

If (a_k1=0)(b_k1=0)(a\_{k-1} = 0) \lor (b\_{k-1} = 0), Jeff considers the answer of the machines to be IC=I \cap C = \varnothing, and if (a_k1=1)(b_k1=1)(a\_{k-1} = 1) \land (b\_{k-1} = 1), Jeff considers the answer of the machines to be ICI \cap C \neq \varnothing.

Jeff struggles to develop such machines. Help him!

입력

The first line contains three integers nn, mm, and kk: the number of vertices in GG, the number of edges in GG, and Jeff's favorite positive integer (1n10001 \le n \le 1000, 1m10,0001 \le m \le 10\\,000, k(log_2(n)+1)2k \ge (\lceil\log\_2 (n)\rceil + 1)^2, knk \le n). The next mm lines contain the description of the edges of GG. Each of these lines contains two integers aa and bb (1a,bn1 \le a, b \le n, aba \neq b). GG does not contain parallel edges.

출력

Print the descriptions of both machines.

A description of a machine should have the following format. The first line of the description should contain one integer tt: the number of nodes in the machine (n+2k+1t1,500,000n + 2k + 1 \le t \le 1\\,500\\,000). The nodes are numbered from 00 to t1t - 1. You should print the descriptions of the non-source nodes. The ii-th of the next t(n+2k)t - (n + 2k) lines should contain the description of the node numbered (i+(n+2k)1)(i + (n + 2k) - 1). The line should contain two integers xx and yy: the left and the right input nodes for node i+(n+2k)1i + (n + 2k) - 1 (0x,y<i0 \le x, y < i), followed by a string f=f_0f_1f_2f_3f = f\_0 f\_1 f\_2 f\_3. The string ff describes the function bb: f_0=b(0,0)f\_0 = b(0, 0), f_1=b(0,1)f\_1 = b(0, 1), f_2=b(1,0)f\_2 = b(1, 0), f_3=b(1,1)f\_3 = b(1, 1). The vertex t1t - 1 is the selected sink of the machine.

This problem is technically interactive (it is sadly so hard to find a clique or an independent set in a graph!), so you need to flush the output after printing the answer to prevent buffering.

힌트

The answer is checked in the following way:

  • The jury picks a clique CC and an independent set II from the given graph.
  • The jury computes the values a_0,b_0,a_1,b_1,,a_k1,b_k1a\_0, b\_0, a\_1, b\_1, \ldots, a\_{k-1}, b\_{k-1} in that order and checks if the boolean expressions (a_k1=0)(b_k1=0)(a\_{k-1} = 0) \lor (b\_{k-1} = 0) and IC=I \cap C = \varnothing have the same value.
  • The process is repeated for several pairs (C,I)(C, I).