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 ℓ is an acyclic directed graph with ℓ 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 v of the graph computes a function f_v:0,1ℓ→0,1. In particular, i-th source s_i computes the function f_s_i(x_1,…,x_n)=x_i. Each inner vertex v is labeled with the function b_v:0,12→0,1. Let u be the starting vertex of the left inner edge to v, and w be the starting vertex of the right inner edge. The function f_v is then defined as f_v(x)=b(f_u(x),f_w(x)). 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) which his uncle John left him. Jeff is really puzzled with cliques and independent sets in this graph.
A set S⊆V is a clique of the graph G=(V,E) if, for every pair of distinct vertices u,v∈S, we have (u,v)∈E.
A set S⊆V is an independent set of the graph G=(V,E) if, for every pair of distinct vertices u,v∈S, we have (u,v)∈E.
Jeff has noticed that if I is an independent set and C is a clique, then ∣I∩C∣≤1. But it still leaves two options: either I∩C=∅ or ∣I∩C∣=1.
Let n=∣V∣. Jeff denotes a vector corresponding to the set S as χ_S∈0,1n: the i-th component of χ_S is 1 if i∈S and 0 otherwise.
Jeff wants to build two machines of order n+2k, where n=∣V∣ and k is Jeff's favorite positive integer, such that they would be able to decide if I∩C=∅ together.
The first machine receives a vector χ_C∈0,1n, where C is a clique, followed by 2k zeroes. The second machine receives a vector χ_I∈0,1n, where I is an independent set, followed by 2k zeroes. After that, the machines will work together using the scheme described below and decide if I∩C=∅.
Let us denote the first machine as A 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,1. Similarly, we denote the second machine as B.
Jeff has developed a scheme to make the machines work together. Let a_0=A(χ_C,0,…,0_2k), b_0=B(χ_I,0,…,0_2k).
Then let a_i=A(χ_C,a_0,b_0,a_1,b_1…,a_i−1,b_i−1,1,0,…,0_2(k−i−1)−1), b_i=B(χ_I,a_0,b_0,a_1,b_1…,a_i−1,b_i−1,1,0,…,0_2(k−i−1)−1).
If (a_k−1=0)∨(b_k−1=0), Jeff considers the answer of the machines to be I∩C=∅, and if (a_k−1=1)∧(b_k−1=1), Jeff considers the answer of the machines to be I∩C=∅.
Jeff struggles to develop such machines. Help him!
The first line contains three integers n, m, and k: the number of vertices in G, the number of edges in G, and Jeff's favorite positive integer (1≤n≤1000, 1≤m≤10,000, k≥(⌈log_2(n)⌉+1)2, k≤n). The next m lines contain the description of the edges of G. Each of these lines contains two integers a and b (1≤a,b≤n, a=b). G 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 t: the number of nodes in the machine (n+2k+1≤t≤1,500,000). The nodes are numbered from 0 to t−1. You should print the descriptions of the non-source nodes. The i-th of the next t−(n+2k) lines should contain the description of the node numbered (i+(n+2k)−1). The line should contain two integers x and y: the left and the right input nodes for node i+(n+2k)−1 (0≤x,y<i), followed by a string f=f_0f_1f_2f_3. The string f describes the function b: f_0=b(0,0), f_1=b(0,1), f_2=b(1,0), f_3=b(1,1). The vertex t−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: