eolymp
bolt
Try our new interface for solving problems
Məsələlər

Thread Tree

Thread Tree

Nathan O. Davis has been running an electronic bulletin board system named JAG-channel. He is now having hard time to add a new feature there - threaded view. Like many other bulletin board systems, JAG-channel is thread-based. Here a thread (also called a topic) refers to a single conversation with a collection of posts. Each post can be an opening post, which initiates a new thread, or a reply to a previous post in an existing thread. Threaded view is a tree-like view that reflects the logical reply structure among the posts: each post forms a node of the tree and contains its replies as its subnodes in the chronological order (i.e. older replies precede newer ones). Note that a post along with its direct and indirect replies forms a subtree as a whole. Let us take an example. Suppose: a user made an opening post with a message hoge; another user replied to it with fuga; yet another user also replied to the opening post with piyo; someone else replied to the second post (i.e. fuga”) with foobar; and the fifth user replied to the same post with jagjag. The tree of this thread would look like: \textbf{hoge} \textbf{├─fuga} \textbf{│ ├─foobar} \textbf{│ └─jagjag} \textbf{└─piyo} For easier implementation, Nathan is thinking of a simpler format: the depth of each post from the opening post is represented by dots. Each reply gets one more dot than its parent post. The tree of the above thread would then look like: \textbf{hoge} \textbf{.fuga} \textbf{..foobar} \textbf{..jagjag} \textbf{.piyo} Your task in this problem is to help Nathan by writing a program that prints a tree in the Nathan's format for the given posts in a single thread. \InputFile Input contains a single dataset in the following format: \textbf{n} \textbf{k_1} \textbf{M_1} \textbf{k_2} \textbf{M_2} \textbf{...} \textbf{k_n} \textbf{M_n} The first line contains an integer \textbf{n} (\textbf{1} ≤ \textbf{n} ≤ \textbf{1000}), which is the number of posts in the thread. Then \textbf{2n} lines follow. Each post is represented by two lines: the first line contains an integer \textbf{k_i} (\textbf{k_1 = 0}, \textbf{1} ≤ \textbf{k_i} < \textbf{i} for \textbf{2} ≤ \textbf{i} ≤ \textbf{n}) and indicates the \textbf{i}-th post is a reply to the \textbf{k_i}-th post; the second line contains a string \textbf{M_i} and represents the message of the \textbf{i}-th post. \textbf{k_1} is always \textbf{0}, which means the first post is not replying to any other post, i.e. it is an opening post. Each message contains \textbf{1} to \textbf{50} characters, consisting of uppercase, lowercase, and numeric letters. \OutputFile Print the given \textbf{n} messages as specified in the problem statement.
Zaman məhdudiyyəti 2 saniyə
Yaddaşı istafadə məhdudiyyəti 256 MiB
Giriş verilənləri #1
1
0
icpc
Çıxış verilənləri #1
icpc
Mənbə Japan Alumni Group Summer Camp 2013 Day 4, 2013/09/23