#hitachi20172a. [hitachi2017_2_a]Problem 2

[hitachi2017_2_a]Problem 2

Problem

In what follows assume we are given two graphs. The first graph G=(V,E)G=(V, E) consists of a set of vertices VV and edges EE. The second graph Gemb=(Vemb,Eemb)G_{emb} = (V_{emb}, E_{emb}) also consists of a set of vertices VembV_{emb} and edges EembE_{emb} and shall be a square King's Graph, with vertices labeled from left to right and top to bottom, as illustrated in the figure below. The task is to find a map ss which assigns each vertex iinVi\\in V to a subset of vertices s(i)Vembs(i) ⊂ V_{emb} such that:

  • For any vertex iinVi \\in V the subgraph induced by s(i)s(i) in GembG_{emb} is connected;
  • The subsets s(i),s(j)Vembs(i), s(j) ⊂ V_{emb} are mutually exclusive, i.e., for any i,jinVi,j \\in V with ineqji\\neq j we have s(i)s(j)=Øs(i)∩ s(j)=Ø;
  • For any vertex iinVi \\in V the subset s(i)s(i) must not be empty.

Score

For each run of your algorithm on a single input graph, the score obtained by the resulting map ss is evaluated as follows:

  • An initial score of 50005000 points is assigned.
  • We add 100100 points to the initial score for each edge (i,j)inE(i,j) \\in E, if the corresponding vertex sets s(i),s(j)Vembs(i), s(j) ⊂ V_{emb} are connected by at least one edge of the King's graph GembG_{emb}.
  • We add a bonus of 100000100000 points, if the algorithm finds a map ss such that for every edge (i,j)inE(i,j)\\in E, the corresponding vertex sets s(i),s(j)Vembs(i), s(j) ⊂ V_{emb} are connected by at least one edge of the King's graph GembG_{emb}. Note that finding a map ss which obtains the bonus score may not be possible on every input graph.
  • Large clusters are penalized by subtracting uinV(s(u)1)∑ _{u \\in V} (|s(u)|-1) points from the score.
  • The score becomes 00 in any of the following cases:
  1. If the subgraph induced by any of the vertex sets s(i)s(i) in GembG_{emb} is disconnected. See Example 1 in the figure below.
  2. If the vertex sets of s(i),s(j)s(i), s(j) are not mutually exclusive, i.e., if any of the vertex sets with (ineqj)(i \\neq j) overlap on some element. See Example 2 in the figure below.
  3. If the subset s(i)s(i) is empty, i.e., s(i)=0|s(i)| = 0.
  4. Furthermore, any run of your algorithm which exceeds either the time or the memory limit will not contribute to your final score. The same is true for any output, which violates the output format specified below.

Two example assignments for which the final score is 00. Example1: The subgraph induced by the upper vertex set (as marked by red rectangles) is disconnected. Example 2: The vertex sets (as marked by a blue and a magenta rectangle) overlap.

  • For the period of the contest we will evaluate your score, by running your algorithm on 30 input graphs GG and adding up the corresponding score. This will allow for a preliminary estimate of your rank.
  • After the contest has finished your final score and rankings will be determined by running your final submission on 150150 previously undisclosed input graphs.

Input

Inputs are given in the following format through the standard input. All the inputs have integer values.

V|V| E|E| u1u_1 v1v_1 u2u_2 v2v_2 : uEu_{|E|} vEv_{|E|} Vemb|V_{emb}| Eemb|E_{emb}| a1a_1 b1b_1 a2a_2 b2b_2 : aEemba_{|E_{emb}|} bEembb_{|E_{emb}|}

  • V|V| and E|E| denote the total number of vertices and edges of the graph GG, respectively.
  • The line ui,viu_i, v_i means that the vertex uiu_i and the vertex viv_i of the graph GG are connected.
  • Vemb|V_{emb}| and Eemb|E_{emb}| denote the total number of vertices and edges of the graph GembG_{emb}, respectively.
  • The line ai,bia_i, b_i means that the vertex aia_i and the vertex bib_i of the graph GembG_{emb} are connected by an edge.

Constraints on the Graph GG

  • 2leqVleq5times1022 \\leq |V| \\leq 5 \\times 10^2
  • $1 \\leq |E| \\leq min ( \\frac{|V| \\times (|V|-1)}{2}, 2 \\times 10^4 )$
  • 1lequiltvileqV1 \\leq u_i \\lt v_i \\leq |V|
  • For any pair ineqji \\neq j, we have that either uinequju_i \\neq u_j or vineqvjv_i \\neq v_j.
  • The graph GG is connected.

Constraints on the Graph GembG_{emb}

  • GembG_{emb} is a square King's graph.
  • 4leqVembleq3.6times1034 \\leq |V_{emb}| \\leq 3.6 \\times 10^3 and Vemb|V_{emb}| is a square number.
  • VleqVemb|V| \\leq |V_{emb}|
  • 1leqailtbileqVemb1 \\leq a_i \\lt b_i \\leq |V_{emb}|

Output

Output should be in the following format consisting of V|V| lines and should be processed through the standard output.

n1n_1 x1,1x_{1,1} x1,2x_{1,2} ... x1,n1x_{1,n_1} n2n_2 x2,1x_{2,1} x2,2x_{2,2} ... x2,n2x_{2,n_2} : nVn_{|V|} xV,1x_{|V|,1} xV,2x_{|V|,2} ... xV,nVx_{|V|,n_{|V|}}

  • The index ii in nin_{i} denotes the ii-th vertex of graph GG.
  • nin_{i} denotes the total number of vertices in s(i)Vembs(i)⊂ V_{emb}, assigned to the ii-th vertex of graph GG.
  • xi,jx_{i,j} denotes the jj-th element of subset s(i)s(i), which is assigned to the ii-th vertex of graph GG.

Constraints for the Output

  • Output should consist of V|V| lines.
  • 1leqni1 \\leq n_i
  • 1leqxi,jleqVemb1 \\leq x_{i,j} \\leq |V_{emb}|
  • ineqji \\neq j or kneqlk \\neq l implies that xi,kneqxj,lx_{i,k} \\neq x_{j,l}

How are the Input Graphs GG Generated

For evaluating your final score, we will run your algorithm on random input graphs GG. These graphs are generated as follows: First, a tree with V|V| vertices is generated randomly. Subsequently, EV+1|E| − |V| + 1 edges are randomly added to the tree. For details see the sample code.


Input Example 1


7 14
1 2
1 3
1 6
1 7
2 4
2 5
2 6
2 7
3 5
3 7
4 5
4 6
4 7
5 7
25 72
1 2
1 6
1 7
2 6
2 3
2 7
2 8
3 7
3 4
3 8
3 9
4 8
4 5
4 9
4 10
5 9
6 7
6 11
6 12
7 11
7 8
7 12
7 13
8 12
8 9
8 13
8 14
9 13
9 10
9 14
9 15
10 14
11 12
11 16
11 17
12 16
12 13
12 17
12 18
13 17
13 14
13 18
13 19
14 18
14 15
14 19
14 20
15 19
16 17
16 21
16 22
17 21
17 18
17 22
17 23
18 22
18 19
18 23
18 24
19 23
19 20
19 24
19 25
20 24
5 10
10 15
15 20
20 25
21 22
22 23
23 24
24 25

Output Example 1


3 14 15 20
1 19
1 9
1 23
1 18
1 25
1 13

The input example 1 from above is visualized in the figure below. The left side shows the input graph with 7 vertices, labeled by indices V1V1 to V7V7. The right side shows a King graph of size 5times55\\times5. The map ss as specified by the output of example 1 is visualized by colored boxes. For example, the vertex V1V1 of the input graph is mapped to a set of three vertices on the kings graph.

We now discuss the score assigned to the map ss as specified by output example 1:

  • The initial score is 50005000 points.
  • We add 11times100=110011 \\times 100 = 1100 points to the initial score, i.e., 100 points for every edge of the input graph, if the corresponding vertex sets are connected by at least one edge of the King's graph. To this end consider for example the edge between the vertex pair (V1,V2)(V1, V2). Clearly, the corresponding vertex sets on the King's graph are connected. Therefore, we add 100 points for this edge. On the other hand, consider the vertex pair (V3,V5)(V3, V5). The corresponding vertex sets on the King's graph are not connected. Therefore, this edge does not contribute to the score and we mark it by a red cross. Repeating this procedure for every edge of the input graph, we find that 1111 edges of this example score, while 33 edges (as marked by a red cross) do not score.
  • The bonus points of output example 1 are 00 because the vertex sets corresponding to some edges of the input graph (as marked by a red cross), are not connected by a direct edge of the King's graph.
  • We subtract $(3-1) + (1-1) + (1-1) + (1-1) + (1-1) + (1-1) + (1-1)= 2$ points, where the first number in each bracket corresponds to the number of elements in each vertex set on the right. Altogether we lose 2 points because the vertex set s(V1)s(V1) contains three elements.
  • Altogether output example 1 scores because the vertex sets s(i)s(i) are mutually exclusive and each vertex set s(i)s(i) induces a connected subgraph of the King's graph.

Input Example 2


10 30
3 10
3 6
5 10
5 8
2 6
2 7
1 5
1 9
4 10
5 7
4 6
2 8
1 2
7 10
2 4
1 3
7 8
1 8
6 9
2 9
1 4
2 10
2 3
6 10
8 10
6 8
5 6
3 8
7 9
4 9
16 42
1 2
1 5
1 6
2 5
2 3
2 6
2 7
3 6
3 4
3 7
3 8
4 7
5 6
5 9
5 10
6 9
6 7
6 10
6 11
7 10
7 8
7 11
7 12
8 11
9 10
9 13
9 14
10 13
10 11
10 14
10 15
11 14
11 12
11 15
11 16
12 15
4 8
8 12
12 16
13 14
14 15
15 16

Output Example 2


1 5
2 7 10
1 1
1 2
1 12
1 6
1 15
1 9
1 4
4 3 8 11 14

The input example 2 corresponds to the following schematic figure.

Sample Code and References

  • Sample code including source code for generating random input graphs and evaluating the corresponding score of your algorithm can be downloaded through the following link.
  • For a previous study of the graph embedding problem, see:

J. Cai, et al., "A practical heuristic for finding graph minors", arXiv:1406.2741 [quant-ph]