题目描述
Problem Description
Tenkaichi Inc. is developing software to visually represent graphs in graph theory. In particular, tools that display less complex graphs in a readable text-based format are popular.
An undirected tree with $ N $ vertices is given. Each vertex is assigned a unique uppercase alphabet letter (the number of vertices is at most $ 26 $).
The $ i $-th of the $ N-1 $ edges connects vertex $ v_i $ and vertex $ w_i $. It is guaranteed that for any vertex, the number of edges connected to that vertex is at most $ 4 $.
Create a program that visually displays the given tree as described below. Details are provided in the "Output Format" section.
```
8 12
............
...D...E....
...|...|....
.C-A---B---F
.|.....|...|
.|.....G.J-I
.H..........
............
## Input Format
The input is given from the standard input in the following format:
> $ N $ $ v_1 $ $ w_1 $ $ v_2 $ $ w_2 $ $ : $ $ v_{N-1} $ $ w_{N-1} $
## Output Format
Display the input tree in $ H+1 $ lines in the following format:
> $ H $ $ W $ $ c_{1,1} $$ c_{1,2} $ $ … $ $ c_{1,W} $ $ c_{2,1} $$ c_{2,2} $ $ … $ $ c_{2,W} $ $ : $ $ c_{H,1} $$ c_{H,2} $ $ … $ $ c_{H,W} $
Where,
- $ H $, $ W $ represent the size of the visual display that follows, separated by a single space. They must satisfy $1≦H≦100,\ 1≦W≦100$.
- The visual display is a rectangular arrangement of characters vertically $ H $ characters and horizontally $ W $ characters.
- Each character $ c_{i,j} $ in the visual display is one of the first $ N $ uppercase English letters, `.` , `-` , or `|`, and must satisfy the following:
- Each vertex of the tree is represented by the corresponding uppercase letter. Each vertex must appear exactly once in the visual display.
- Characters representing vertices must not be adjacent vertically or horizontally to characters representing other vertices.
- If two vertices $a,\ b$ are directly connected by an edge, one of the following conditions **(A)**, **(B)** must be satisfied:
- **(A)** The two characters representing vertices $a,\ b$ are in the same row of the visual display, and all characters between them are `-`.
- **(B)** The two characters representing vertices $a,\ b$ are in the same column of the visual display, and all characters between them are `|`.
- If two vertices $a,\ b$ are not directly connected by an edge, neither of the above conditions **(A)**, **(B)** should be satisfied.
- All characters not representing vertices or edges must be `.` .
It can be shown that for inputs satisfying the constraints, there always exists a visual display satisfying these conditions. Any such visual display may be output.
## Sample Input and Output
### Sample Input #1
10
A B
A C
A D
B E
B F
B G
C H
F I
I J
### Sample Output #1
8 12
............
...D...E....
...|...|....
.C-A---B---F
.|.....|...|
.|.....G.J-I
.H..........
............
### Sample Input #2
7
A B
B C
C D
D E
E F
F G
### Sample Output #2
5 4
.A-B
E-F|
|.||
|.G|
D--C
```
Notes/Hints
Constraints
- $ 2≦N≦26 $
- $ v_i $, $ w_i $ are each one of the first $ N $ uppercase letters.
- The given graph is a tree.
- For any vertex, the number of edges connected to that vertex is at most $ 4 $.
Sample Explanation 1
The output example is the same as the one provided in the problem statement.
Sample Explanation 2
Characters representing vertices are not prohibited from being adjacent vertically or horizontally to - or |.
输入格式
见题面 Input 部分
输出格式
见题面 Output 部分