Intrusion Detection System

Time limit: 2s Memory limit: 512MB Input: Output:

Lately William started going out clubbing and, as a result, he became very interested in lasers and laser-related systems. This new expertise came in handy, now that some of the IOIT participant teams started harassing him and Giorgio trying to extort hints about the tasks!

William is now building an Intrusion Detection System (IDS) to ensure that nobody can access their hotel room and steal classified information about the tasks.

William and Giorgio’s hotel room is HH meters long and WW meters wide. We can represent it as a HWH \cdot W grid where each cell might contain a laser connector (which is both emitter and receiver).

In order for two connectors to “see” each other (and shoot lasers at each other) they must be lined up either horizontally or vertically: our lasers can’t go diagonally. Two connectors can’t see each other if there are other connectors “blocking the view”; the light beams, however, can intersect.

William has just designed a graph on the whiteboard, consisting of NN vertices and MM edges. He would like to introduce a laser connector on the grid for every vertex in the graph, and a laser beam (between two connectors) for every edge in the graph. We will call this a laser arrangement of the graph.

It’s always possible to find a complete laser arrangement (where all vertices and edges are used) for the graph designed by William. However, he will be happy enough with a partial arrangement: something is better than nothing, to stop those mischievous participants!

Input data

The first line contains integers HH and WW. The second line contains integers NN and MM. The following MM lines contain two integers each: AiA_i and BiB_i, both of them between 00 and N1N - 1, which represent a direct (and bidirectional) laser connection between vertex AiA_i and vertex BiB_i.

Output data

You need to write the board you produced, that is: HH lines with WW integers each. The jj-th integer of the ii-th line will be either:

  • A dot character . if the respective cell in the board is left empty.
  • Some non-negative integer uu, if you decide to put vertex uu in that cell.

Note that in a partial laser arrangement you don’t need to put all vertices in the grid: some may be ignored. That is: if you only print dots, it’s still a valid partial arrangement!

Moreover: if you want, you can put more spaces between cells for alignment purposes and they will be ignored. In the examples section we sometimes use two spaces instead of one.

Constraints and clarifications

  • 1H,W1 0001 \leq H, W \leq 1 \ 000.
  • 1N,M121 \leq N, M \leq 12.
  • 0Ai,BiN10 \leq A_i, B_i \leq N − 1 for each i=0N1i = 0 \dots N − 1.
  • There are no self loops (Ai=BiA_i = B_i) and no duplicate edges.
  • The graph may not be connected.

Your program will be tested against several test cases grouped in subtasks. The score in each subtask will be calculated as the minimum score obtained in any of its test cases, multiplied by the value of the subtask. The score in a test case will be calculated as: MΔoutM+10Δout\frac{M − \Delta_{out}}{M + 10 \cdot \Delta_{out}}, where Δout\Delta_{out} is the difference between the number of connections established by your solution and MM.

# Score Constraints
1 5 Examples
2 15 H=1H = 1
3 20 H,W10H, W \leq 10, M5M \leq 5
4 20 H,W4H, W \leq 4
5 20 H,W10H, W \leq 10
6 20 No additional limitations.

Example 1

stdin

2 3
4 4
0 1
2 3
2 1
0 3

stdout

0 3 .
1 2 .

Explanation

In the first sample case the presented solution is optimal.

Example 2

stdin

4 4
11 10
1 4
0 1
7 2
8 6
6 10
5 7
4 2
3 10
10 9
6 0

stdout

1 0 7 5
4 . 2 .
8 6 10 9
. . 3 .

Explanation

In the second sample case the presented solution is optimal.

Example 3

stdin

4 4
11 10
1 4
0 1
7 2
8 6
6 10
5 7
4 2
3 10
10 9
6 0

stdout

1 0 7 5
4 . 2 .
6 . 10 .
. . 3 9

Explanation

In the third sample case the presented solution establishes 77 laser connections out of 1010, thus scoring: 10310+103=740=0.175\frac{10 - 3}{10 + 10 \cdot 3} = \frac{7}{40} = 0.175 out of a maximum of 11 point.

Log in or sign up to be able to send submissions!