This page is still under construction.

Parts of this page are still being built. What you see may change.

Rail Station Recovery

Time limit3sMemory limit512 MB

Summary
Recover every station's block number and C or D type from the all-pairs shortest-route distances and station 0's block.
Level

Hard9 of 10

Topics
Graph, Sorting, Math
Solved
No attempts yet

Problem

A railway line runs from the western end of the island to the eastern end and consists of mm blocks. The blocks are numbered 00, 11, ..., m−1m-1 from the west. Each block has a one way westbound track on its north side, a one way eastbound track on its south side, and possibly one station between the two tracks.

A block has one of three types. A type C block holds a station that you enter from the northern track and leave onto the southern track. A type D block holds a station that you enter from the southern track and leave onto the northern track. An empty block has no station. The tracks of two neighboring blocks are joined by a connector. In the figure below the connectors are the gray rectangles.

The line in the figure has 7 blocks. Blocks 11, 22 and 33 are type C, block 55 is type D, and the other blocks are empty. It has 4 stations: station 00 sits in block 22, station 11 in block 55, station 22 in block 33, and station 33 in block 11.

The line has nn stations, numbered 00 to n−1n-1. From every station you can reach every other station along the tracks. Several routes join one station to another, so the distance between two stations is the smallest number of connectors a route passes. In the figure the shortest route from station 0 to station 2 runs through blocks 2, 3, 4, 5, 4, 3 and passes 5 connectors, so the distance between those two stations is 55.

After a power outage the computer that manages the line lost the block number and the block type of every station. The only clue left is the block number of station 00, and that block is always type C. The computer can still measure the distance between every pair of stations. Recover the block number and the block type of every station from the distance table and the block number of station 00.

Input

The first line has the number of stations nn and the block number ff of station 00, separated by a space. Each of the next nn lines holds one row of the distance table. The jj-th number on the ii-th of those lines is the distance between station i−1i-1 and station j−1j-1.

  • 2≤n≤1002 \le n \le 100
  • 0≤f<1090 \le f < 10^9
  • Every station has a block number that is at least 00 and less than 10910^9, and a block holds at most one station.
  • The distance table is symmetric and every diagonal entry is 00.
  • The input comes from a line that meets all of the conditions above, and only one arrangement of stations produces it.

Output

Print nn lines. The ii-th line holds the block number of station i−1i-1 and the type of that block, separated by a single space. Write C for a type C block and D for a type D block.

Examples4

  1. Example 1

    Input
    4 2
    0 3 5 7
    3 0 2 4
    5 2 0 6
    7 4 6 0
    
    Expected output
    2 C
    5 D
    3 C
    1 C
    
  2. Example 2

    Input
    2 0
    0 1
    1 0
    
    Expected output
    0 C
    1 D
    
  3. Example 3

    Input
    5 3
    0 6 5 1 8
    6 0 9 7 2
    5 9 0 4 11
    1 7 4 0 9
    8 2 11 9 0
    
    Expected output
    3 C
    9 D
    0 C
    4 D
    7 C
    
  4. Example 4

    Input
    3 5
    0 7 1
    7 0 6
    1 6 0
    
    Expected output
    5 C
    0 C
    6 D