Problem:
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:
hoge
├─fuga
│　├─foobar
│　└─jagjag
└─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:
hoge
.fuga
..foobar
..jagjag
.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.
Input
Input contains a single dataset in the following format:
n
k_1
M_1
k_2
M_2
:
:
k_n
M_n
The first line contains an integer
n
(
1 ≤ n ≤ 1,000
), which is the number of posts in the thread.
Then
2n
lines follow.
Each post is represented by two lines:
the first line contains an integer
k_i
(
k_1 = 0
,
1 ≤ k_i < i
for
2 ≤ i ≤ n
) and indicates the
i
-th post is a reply to the
k_i
-th post;
the second line contains a string
M_i
and represents the message of the
i
-th post.
k_1
is always 0, which means the first post is not replying to any other post, i.e. it is an opening post.
Each message contains 1 to 50 characters, consisting of uppercase, lowercase, and numeric letters.
Output
Print the given
n
messages as specified in the problem statement.
Sample Input 1
1
0
icpc
Output for the Sample Input 1
icpc
Sample Input 2
5
0
hoge
1
fuga
1
piyo
2
foobar
2
jagjag
Output for the Sample Input 2
hoge
.fuga
..foobar
..jagjag
.piyo
Sample Input 3
8
0
jagjag
1
hogehoge
1
buhihi
2
fugafuga
4
ponyoponyo
5
evaeva
4
nowawa
5
pokemon
Output for the Sample Input 3
jagjag
.hogehoge
..fugafuga
...ponyoponyo
....evaeva
....pokemon
...nowawa
.buhihi
Sample Input 4
6
0
nakachan
1
fan
2
yamemasu
3
nennryou2
4
dannyaku4
5
kouzai11
Output for the Sample Input 4
nakachan
.fan
..yamemasu
...nennryou2
....dannyaku4
.....kouzai11
Sample Input 5
34
0
LoveLive
1
honoka
2
borarara
2
sunohare
2
mogyu
1
eri
6
kasikoi
7
kawaii
8
e
...(truncated)

Submitted solutions:

code_snippet: #include <bits/stdc++.h>

using namespace std;

#define rep(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rrep(i, a, b) for (int i = (int)(b)-1; i >= (int)(a); i--)
#define ALL(v) (v).begin(), (v).end()
#define UNIQUE(v) sort(ALL(v)), (v).erase(unique(ALL(v)), (v).end())
#define SZ(v) (int)v.size()
#define MIN(v) *min_element(ALL(v))
#define MAX(v) *max_element(ALL(v))
#define LB(v, x) int(lower_bound(ALL(v), (x)) - (v).begin())
#define UB(v, x) int(upper_bound(ALL(v), (x)) - (v).begin())

using uint = unsigned int;
using ll = long long int;
using ull = unsigned long long;
using i128 = __int128_t;
using u128 = __uint128_t;
const int inf = 0x3fffffff;
const ll INF = 0x1fffffffffffffff;

template <typename T> inline bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T> inline bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T, typename U> T ceil(T x, U y) {
    assert(y != 0);
    if (y < 0)
        x = -x, y = -y;
    return (x > 0 ? (x + y - 1) / y : x / y);
}
template <typename T, typename U> T floor(T x, U y) {
    assert(y != 0);
    if (y < 0)
        x = -x, y = -y;
    return (x > 0 ? x / y : (x - y + 1) / y);
}
template <typename T> int popcnt(T x) {
    return __builtin_popcountll(x);
}
template <typename T> int topbit(T x) {
    return (x == 0 ? -1 : 63 - __builtin_clzll(x));
}
template <typename T> int lowbit(T x) {
    return (x == 0 ? -1 : __builtin_ctzll(x));
}

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
    os << "P(" << p.first << ", " << p.second << ")";
    return os;
}
template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec) {
    os << "{";
    for (int i = 0; i < vec.size(); i++) {
        os << vec[i] << (i + 1 == vec.size() ? "" : ", ");
    }
    os << "}";
    return os;
}
template <typename T, typename U>
ostream &operator<<(ostream &os, const map<T, U> &map_var) {
    os << "{";
    for (auto itr = map_var.begin(); itr != map_var.end(); itr++) {
        os << "(" << itr->first << ", " << itr->second << ")";
        itr++;
        if (itr != map_var.end())
            os << ", ";
        itr--;
    }
    os << "}";
    return os;
}
template <typename T> ostream &operator<<(ostream &os, const set<T> &set_var) {
    os << "{";
    for (auto itr = set_var.begin(); itr != set_var.end(); itr++) {
        os << *itr;
        ++itr;
        if (itr != set_var.end())
            os << ", ";
        itr--;
    }
    os << "}";
    return os;
}
#ifdef LOCAL
#define show(...) _show(0, #__VA_ARGS__, __VA_ARGS__)
#else
#define show(...) true
#endif
template <typename T> void _show(int i, T name) {
    cerr << '\n';
}
template <typename T1, typename T2, typename... T3>
void _show(int i, const T1 &a, const T2 &b, const T3 &...c) {
    for (; a[i] != ',' && a[i] != '\0'; i++)
        cerr << a[i];
    cerr << ":" << b << " ";
    _show(i + 1, a, c...);
}

#include <unistd.h>

namespace fastio {
static constexpr uint32_t SZ = 1 << 17;
char ibuf[SZ];
char obuf[SZ];
char out[100];
// pointer of ibuf, obuf


uint32_t pil = 0, pir = 0, por = 0;

struct Pre {
    char num[10000][4];
    constexpr Pre() : num() {
        for (int i = 0; i < 10000; i++) {
            int n = i;
            for (int j = 3; j >= 0; j--) {
                num[i][j] = n % 10 | '0';
                n /= 10;
            }
        }
    }
} constexpr pre;

inline void load() {
    memmove(ibuf, ibuf + pil, pir - pil);
    pir = pir - pil + fread(ibuf + pir - pil, 1, SZ - pir + pil, stdin);
    pil = 0;
    if (pir < SZ)
        ibuf[pir++] = '\n';
}

inline void flush() {
    fwrite(obuf, 1, por, stdout);
    por = 0;
}

void rd(char &c) {
    do {
        if (pil + 1 > pir)
            load();
        c = ibuf[pil++];
    } while (isspace(c));
}

void rd(string &x) {
    x.clear();
    char c;
    do {
        if (pil + 1 > pir)
            load();
        c = ibuf[pil++];
    } while (isspace(c));
    do {
        x += c;
        if (pil == pir)
            load();
        c = ibuf[pil++];
    } while (!isspace(c));
}

template <typename T> void rd_real(T &x) {
    string s;
    rd(s);
    x = stod(s);
}

template <typename T> void rd_integer(T &x) {
    if (pil + 100 > pir)
        load();
    char c;
    do
        c = ibuf[pil++];
    while (c < '-');
    bool minus = 0;
    if constexpr (is_signed<T>::value || is_same_v<T, i128>) {
        if (c == '-') {
            minus = 1, c = ibuf[pil++];
        }
    }
    x = 0;
    while ('0' <= c) {
        x = x * 10 + (c & 15), c = ibuf[pil++];
    }
    if constexpr (is_signed<T>::value || is_same_v<T, i128>) {
        if (minus)
            x = -x;
    }
}

void rd(int &x) {
    rd_integer(x);
}
void rd(ll &x) {
    rd_integer(x);
}
void rd(i128 &x) {
    rd_integer(x);
}
void rd(uint &x) {
    rd_integer(x);
}
void rd(ull &x) {
    rd_integer(x);
}
void rd(u128 &x) {
    rd_integer(x);
}
void rd(double &x) {
    rd_real(x);
}
void rd(long double &x) {
    rd_real(x);
}

template <class T, class U> void rd(pair<T, U> &p) {
    return rd(p.first), rd(p.second);
}
template <size_t N = 0, typename T> void rd_tuple(T &t) {
    if constexpr (N < std::tuple_size<T>::value) {
        auto &x = std::get<N>(t);
        rd(x);
        rd_tuple<N + 1>(t);
    }
}
template <class... T> void rd(tuple<T...> &tpl) {
    rd_tuple(tpl);
}

template <size_t N = 0, typename T> void rd(array<T, N> &x) {
    for (auto &d : x)
        rd(d);
}
template <class T> void rd(vector<T> &x) {
    for (auto &d : x)
        rd(d);
}

void read() {}
template <class H, class... T> void read(H &h, T &...t) {
    rd(h), read(t...);
}

void wt(const char c) {
    if (por == SZ)
        flush();
    obuf[por++] = c;
}
void wt(const string s) {
    for (char c : s)
        wt(c);
}
void wt(const char *s) {
    size_t len = strlen(s);
    for (size_t i = 0; i < len; i++)
        wt(s[i]);
}

template <typename T> void wt_integer(T x) {
    if (por > SZ - 100)
        flush();
    if (x < 0) {
        obuf[por++] = '-', x = -x;
    }
    int outi;
    for (outi = 96; x >= 10000; outi -= 4) {
        memcpy(out + outi, pre.num[x % 10000], 4);
        x /= 10000;
    }
    if (x >= 1000) {
        memcpy(obuf + por, pre.num[x], 4);
        por += 4;
    } else if (x >= 100) {
        memcpy(obuf + por, pre.num[x] + 1, 3);
        por += 3;
    } else if (x >= 10) {
        int q = (x * 103) >> 10;
        obuf[por] = q | '0';
        obuf[por + 1] = (x - q * 10) | '0';
        por += 2;
    } else
        obuf[por++] = x | '0';
    memcpy(obuf + por, out + outi + 4, 96 - outi);
    por += 96 - outi;
}

template <typename T> void wt_real(T x) {
    ostringstream oss;
    oss << fixed << setprecision(15) << double(x);
    string s = oss.str();
    wt(s);
}

void wt(int x) {
    wt_integer(x);
}
void wt(ll x) {
    wt_integer(x);
}
void wt(i128 x) {
    wt_integer(x);
}
void wt(uint x) {
    wt_integer(x);
}
void wt(ull x) {
    wt_integer(x);
}
void wt(u128 x) {
    wt_integer(x);
}
void wt(double x) {
    wt_real(x);
}
void wt(long double x) {
    wt_real(x);
}

template <class T, class U> void wt(const pair<T, U> val) {
    wt(val.first);
    wt(' ');
    wt(val.second);
}
template <size_t N = 0, typename T> void wt_tuple(const T t) {
    if constexpr (N < std::tuple_size<T>::value) {
        if constexpr (N > 0) {
            wt(' ');
        }
        const auto x = std::get<N>(t);
        wt(x);
        wt_tuple<N + 1>(t);
    }
}
template <class... T> void wt(tuple<T...> tpl) {
    wt_tuple(tpl);
}
template <class T, size_t S> void wt(const array<T, S> val) {
    auto n = val.size();
    for (size_t i = 0; i < n; i++) {
        if (i)
            wt(' ');
        wt(val[i]);
    }
}
template <class T> void wt(const vector<T> val) {
    auto n = val.size();
    for (size_t i = 0; i < n; i++) {
        if (i)
            wt(' ');
        wt(val[i]);
    }
}

void print() {
    wt('\n');
}
template <class Head, class... Tail> void print(Head &&head, Tail &&...tail) {
    wt(head);
    if (sizeof...(Tail))
        wt(' ');
    print(forward<Tail>(tail)...);
}
void __attribute__((destructor)) _d() {
    flush();
}
} // namespace fastio


using fastio::flush;
using fastio::print;
using fastio::read;

inline void first(bool i = true) {
    print(i ? "first" : "second");
}
inline void Alice(bool i = true) {
    print(i ? "Alice" : "Bob");
}
inline void Takahashi(bool i = true) {
    print(i ? "Takahashi" : "Aoki");
}
inline void yes(bool i = true) {
    print(i ? "yes" : "no");
}
inline void Yes(bool i = true) {
    print(i ? "Yes" : "No");
}
inline void No() {
    print("No");
}
inline void YES(bool i = true) {
    print(i ? "YES" : "NO");
}
inline void NO() {
    print("NO");
}
inline void Yay(bool i = true) {
    print(i ? "Yay!" : ":(");
}
inline void Possible(bool i = true) {
    print(i ? "Possible" : "Impossible");
}
inline void POSSIBLE(bool i = true) {
    print(i ? "POSSIBLE" : "IMPOSSIBLE");
}

/**
 * @brief Fast IO
 */

int N;
vector<int> A;
vector<string> S;
vector<vector<int>> G;

void DFS(int X, int Dep) {
    rep(i,0,Dep) cout << '.';
    cout << S[X];
    cout << endl;
    for (int Y : G[X]) DFS(Y,Dep+1);
}

int main() {
    cin >> N;
    A.resize(N), S.resize(N);
    rep(i,0,N) cin >> A[i] >> S[i], A[i]--;
    G.resize(N);
    rep(i,1,N) G[A[i]].push_back(i);
    DFS(0,0);
}
accuracy: 1
time_ms: 10
memory_kb: 3628
final_rank: 14

code_snippet: #include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=a;i<b;i++)
using ll = long long;
#define all(p) p.begin(),p.end()

int main(){
	int n;
	cin>>n;
	vector<vector<int>> G(n);
	vector<string> S(n);
	rep(i,0,n){
		int k;
		cin>>k>>S[i];
		if(i) G[k-1].push_back(i);
	}
	auto f=[&](auto self,int d,int a)->void{
		rep(i,0,d) cout<<".";
		cout<<S[a]<<"\n";
		for(auto x:G[a]) self(self,d+1,x);
	};
	f(f,0,0);
}
accuracy: 1
time_ms: 10
memory_kb: 3592
final_rank: 13

code_snippet: #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll =vector<vll>;
#define rep(i, n) for (ll i = 0; i < (ll) (n); i++)

vector<string> S;
vll dist;
void dfs(vvll &G,ll n){
    rep(i,dist[n])cout<<'.';
    cout<<S[n]<<endl;
    for(auto v:G[n])dfs(G,v);
}

int main() {
    ll N;
    cin>>N;
    vvll G(N);
    S.resize(N);
    dist.assign(N,0);
    rep(i,N){
        ll A;
        cin>>A>>S[i];
        if(i==0)continue;
        A--;
        dist[i]=dist[A]+1;
        G[A].push_back(i);
    }
    dfs(G,0);
}
accuracy: 1
time_ms: 10
memory_kb: 3656
final_rank: 15

code_snippet: #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, string> pint;
#define rep(i, n) for(ll i = 0; i < (ll)n; i++)
#define ALL(v) (v).begin(), (v).end()


vector<pint> graph[2010];

void dfs(ll v, ll cnt) {
  for(auto c: graph[v]) {
    rep(i, cnt) cout << '.';
    cout << c.second << endl;
    dfs(c.first, cnt+1);
  }
}

int main() {
  ll N; cin >> N;
  rep(i, N) {
    ll K; cin >> K;
    string S; cin >> S;
    graph[K].push_back(pint(i+1, S));
  }
  dfs(0, 0);
}
accuracy: 1
time_ms: 10
memory_kb: 3764
final_rank: 18

code_snippet: #include <bits/stdc++.h>
using namespace std;

#define REP(i,n) for(int i=0;i<(n);i++)
#define ALL(v) v.begin(),v.end()

typedef pair<int,string> P;
vector<vector<P>> g;
void dfs(int idx,int t){
  for(P p:g[idx]){
    REP(_,t)cout<<".";
    cout<<p.second<<endl;
    dfs(p.first,t+1);
  }
}

int main(){
  int n;cin>>n;
  g.resize(n+1);
  REP(i,n){
    int a;cin>>a;
    string s;cin>>s;
    g[a].push_back(P(i+1,s));
  }
  dfs(0,0);
}
accuracy: 1
time_ms: 10
memory_kb: 3788
final_rank: 19

code_snippet: #include <bits/stdc++.h>
using namespace std;

void dfs(vector<vector<int>> &G, vector<string> &s, int v, vector<bool> &visit, int d) {
  visit.at(v) = true;
  for (int i = 0; i < d; i++) cout << ".";
  cout << s.at(v) << '\n';
  for (int i = 0; i < G[v].size(); i++) {
    if (visit[G[v][i]] == false) dfs(G, s, G[v][i], visit, d + 1);
  }
  return;
}

int main() {
  int n;
  cin >> n;
  
  vector<vector<int>> G(n);
  vector<string> s(n);
  for (int i = 0; i < n; i++) {
    int k;
    cin >> k >> s.at(i);
    if (i) G[k - 1].emplace_back(i);
  }
  
  vector<bool> visit(n, false);
  dfs(G, s, 0, visit, 0);
}
accuracy: 1
time_ms: 10
memory_kb: 3684
final_rank: 17

code_snippet: #include <bits/stdc++.h>
using namespace std;

vector<vector<int>> G;
vector<string> M;

void book(int id = 0, int depth = 0) {
    for (int i = 0; i < depth; i++) {
        cout << '.';
    }
    cout << M[id] << endl;
    for (auto& nxt : G[id])
        book(nxt, depth + 1);
}

int main() {
    int N;
    cin >> N;
    G.resize(N);
    M.resize(N);
    for (int i = 0; i < N; i++) {
        int k;
        string S;
        cin >> k >> S;
        k--;
        if (k >= 0)
            G[k].emplace_back(i);
        M[i] = S;
    }

    book();
}
accuracy: 1
time_ms: 10
memory_kb: 3656
final_rank: 15

code_snippet: // Thread Tree (200)
// 2020/11/26

#include <bits/stdc++.h>

using namespace std;

struct ThreadTree
{
    int depth;
    string message;
    vector<ThreadTree *> subnodes;

    ThreadTree(int d, string m)
    {
        depth = d;
        message = m;
    }

    void add_subnode(ThreadTree *tree)
    {
        subnodes.push_back(tree);
    }

    void print()
    {
        for (int i = 0; i < depth; i++)
            cout << ".";
        cout << message << endl;
        for (ThreadTree *subnode : subnodes)
            subnode->print();
    }
};

int main()
{
    int n;
    cin >> n;

    vector<ThreadTree *> trees;

    int k;
    cin >> k;
    assert(k == 0);
    string message;
    cin >> message;
    trees.push_back(new ThreadTree(0, message));
    for (int i = 1; i < n; i++)
    {
        int k;
        cin >> k;
        string message;
        cin >> message;
        ThreadTree *tree = new ThreadTree(trees[k - 1]->depth + 1, message);
        trees[k - 1]->add_subnode(tree);
        trees.push_back(tree);
    }

    trees[0]->print();
}
accuracy: 1
time_ms: 10
memory_kb: 3376
final_rank: 2

code_snippet: #include <bits/stdc++.h>

#pragma GCC target("avx2")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
//#include <boost/multiprecision/cpp_int.hpp>
using namespace std;

//using namespace boost::multiprecision;
//#include<atcoder/all>
//using namespace atcoder;

using dou =long double;
string yes="yes";
string Yes="Yes";
string YES="YES";
string no="no";
string No="No";
string NO="NO";

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

const ll mod = 998244353ll;
//const ll mod = 1000000007ll;
//const ll mod = 100000;


struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime modhttps://atcoder.jp/contests/abc166/submit?taskScreenName=abc166_f
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};

istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

#define rep(i, n)         for(ll i = 0; i < (ll)(n); i++)
//#define rep(i, n)         for(int i = 0; i < (int)(n); i++)
#define brep(n)           for(int bit=0;bit<(1<<n);bit++)
#define bbrep(n)           for(int bbit=0;bbit<(1<<n);bbit++)
#define erep(i,container) for (auto &i : container)
#define itrep(i,container) for (auto i : container)
#define irep(i, n)        for(ll i = n-1; i >= (ll)0ll; i--)
#define rrep(i,m,n) for(ll i = m; i < (ll)(n); i++)
#define reprep(i,j,h,w) rep(i,h)rep(j,w)
#define repreprep(i,j,k,h,w,n) rep(i,h)rep(j,w)rep(k,n)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define VEC(type,name,n) std::vector<type> name(n);rep(i,n)std::cin >> name[i];
#define pb push_back
#define pf push_front
#define query int qq;std::cin >> qq;rep(qqq,qq)
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define itn int
#define mp make_pair
//#define sum(a) accumulate(all(a),0ll)
#define keta fixed<<setprecision
#define kout(d) std::cout << keta(10)<< d<< std::endl;
#define vout(a) erep(qxqxqx,a)std::cout << qxqxqx << ' ';std::cout  << std::endl;
#define vvector(name,typ,m,n,a)vector<vector<typ> > name(m,vector<typ> (n,a))
//#define vvector(name,typ,m,n)vector<vector<typ> > name(m,vector<typ> (n))
#define vvvector(name,t,l,m,n,a) vector<vector<vector<t> > > name(l, vector<vector<t> >(m, vector<t>(n,a)));
#define vvvvector(name,t,k,l,m,n,a) vector<vector<vector<vector<t> > > > name(k,vector<vector<vector<t> > >(l, vector<vector<t> >(m, vector<t>(n,a)) ));
#define case std::cout <<"Case #" <<qqq+1<<":"
#define RES(a,i,j) a.resize(i);rep(ii,i)a[ii].resize(j);

#define RESRES(a,i,j,k) a.resize(i);rep(ii,i)a[ii].resize(j);reprep(ii,jj,i,j){a[ii][jj].resize(k);};
#define res resize
#define as assign
#define ffor for(;;)
#define ppri(a,b) std::cout << a<<" "<<b << std::endl
#define pppri(a,b,c) std::cout << a<<" "<<b <<" "<< c<<std::endl
#define ppppri(a,b,c,d) std::cout << a<<" "<<b <<" "<< c<<' '<<d<<std::endl
#define aall(x,n) (x).begin(),(x).begin()+(n)
#define SUM(a) accumulate(all(a),0ll) 
#define stirng string
#define gin(a,b) int a,b;std::cin >> a>>b;a--;b--;
#define popcount __builtin_popcount
#define permu(a) next_permutation(all(a))
#define aru(a,d) a.find(d)!=a.end()
#define nai(a,d) a.find(d)==a.end()
//#define aru p.find(mp(x,y))!=p.end()

//#define grid_input(a,type) int h,w;std::cin >> h>>w;vvector(a,type,h,w,0);reprep(i,j,h,w)std::cin >> a[i][j];

//typedef long long T;
ll ceili(ll a,ll b){
    return ((a+b-1)/b);
}
const int INF = 2'000'000'000;
const ll INF64 =32233720854775807ll;
//const ll INF64 = 9223372036854775807ll;

//const ll INF64 = 243'000'000'000'000'000'0;Q


//const ll MOD = 100'000'000'7ll;
const ll MOD = 998244353ll;
//const ll MOD = 1000003ll;
const ll OD = 1000000000000007ll;
const dou pi=3.141592653589793;

long long modpow(long long a, long long n) { 
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % MOD;
        a = a * a % MOD;
        n >>= 1;
    }
    return res;
}
//メモ
//ゲーム(Grundy数とか)の復習をする
//リスニング力をどうにかする
//個数制限付きナップサックの復習
//戻すDP
//全方位木DPとスライド最小値
//学会しゃべる練習をする
//llig 連続写真の三枚目を使ったほうがわかりやすいかも！
//自分の新規性の強調

//LCAと，それを活用して頂点間の距離をO(log N)で求めることができる
//add_edge(from,to):from,toの間に無向辺を追加する
//build(): 加えられた辺の情報を用いてデータ構造を構築する
//lca(u,v):u,vの LCA を求める
//dist(u,v):u,v間のキョリを求める
template<typename T> class segtree {
private:
    int n,sz;
    vector<pair<T, int> > node;
public:
    void resize(vector<T>& v){
        sz = (int)v.size();
        n = 1;
        while(n < sz){
            n *= 2;
        }
        node.resize(2*n);
        for(int i = 0; i < sz; i++){
            node[i+n] = make_pair(v[i], i);
        }
        for(int i=n-1; i>=1; i--){
            node[i] = min(node[2*i], node[2*i+1]);
        }
    }
    void update(int k, T a)
    {
    	node[k+=n] = make_pair(a, k);
    	while(k>>=1){
            node[k] = min(node[2*k], node[2*k+1]);
    	}
    }
    pair<T, int> qquery(int a,int b)
    {
        pair<T, int> res1 = make_pair(numeric_limits<T>::max(), -1);
        pair<T, int> res2 = make_pair(numeric_limits<T>::max(), -1);
        a += n, b += n;
        while(a != b){
            if(a % 2) res1 = min(res1, node[a++]);
            if(b % 2) res2 = min(res2, node[--b]);
            a >>= 1, b >>= 1;
        }
        return min(res1, res2);
    }
};

class LCA{
private:
    int V;
    vector<vector<int> > G;
    vector<int> ord,depth,id;
    segtree<int> st;
    void dfs(int u,int p,int k){
        id[u] = (int)ord.size();
        ord.push_back(u);
        depth[u] = k;
        for(int v : G[u]){
            if(v != p){
                dfs(v,u,k+1);
                ord.push_back(u);
            }
        }
    }

public:
    LCA(int node_size) : V(node_size), G(V), depth(V), id(V, -1){}
   // void LLCA(int node_size) : V(node_size), G(V), depth(V), id(V, -1){}
    void add_edge(int from,int to){
        G[from].push_back(to),G[to].push_back(from);
    }
    void build(){
        ord.reserve(2*V-2);
        for(int i = 0; i < V; i++){
            if(id[i] < 0){
                dfs(i,-1,0);
            }
        }
        vector<int> stvec(2*V-2);
    	for(int i = 0; i < 2*V-2; i++){
    		stvec[i] = depth[ord[i]];
    	}
        st.resize(stvec);
    }
    int lca(int u,int v){
        return ord[st.qquery(min(id[u],id[v]),max(id[u],id[v])+1).second];
    }
    int dist(int u,int v){
        int lca_ = lca(u,v);
        return depth[u] + depth[v] - 2*depth[lca_];
    }
};
//LCAと，それを活用して頂点間の距離をO(log N)で求めることができる
//add_edge(from,to):from,toの間に無向辺を追加する
//build(): 加えられた辺の情報を用いてデータ構造を構築する
//lca(u,v):u,vの LCA を求める
//dist(u,v):u,v間のキョリを求める
//LCAここまで

std::vector<std::vector<int>>g;
std::vector<string> s;
LCA l(1010);

void dfs(int p){
    int c=l.dist(0,p);
    rep(i,c)std::cout << '.';
    std::cout << s[p] << std::endl;
    erep(i,g[p]){
        dfs(i);
    }
    return ;
}



int main(){
    int n;
    std::cin >> n;
    //l.LLCA(n);
    g.resize(n);
    s.resize(n);
    rep(i,n){
        int d;
        std::cin >> d;
        if(i!=0){
            g[d-1].pb(i);
            l.add_edge(i,d-1);
        }
        std::cin >> s[i];
    }
    l.build();
    dfs(0);
}
accuracy: 1
time_ms: 10
memory_kb: 3584
final_rank: 12

code_snippet: #include <bits/stdc++.h>
using namespace std;

#define int long long
//typedef long long i64;

// debug methods
// usage: debug(x,y);
#define CHOOSE(a) CHOOSE2 a
#define CHOOSE2(a0,a1,a2,a3,a4,x,...) x
#define debug_1(x1) cout<<#x1<<": "<<x1<<'\n'
#define debug_2(x1,x2) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<'\n'
#define debug_3(x1,x2,x3) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<'\n'
#define debug_4(x1,x2,x3,x4) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<", "#x4<<": "<<x4<<'\n'
#define debug_5(x1,x2,x3,x4,x5) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<", "#x4<<": "<<x4<<", "#x5<<": "<<x5<<'\n'
#ifdef _DEBUG
#define debug(...) CHOOSE((__VA_ARGS__,debug_5,debug_4,debug_3,debug_2,debug_1,~))(__VA_ARGS__)
#else
#define debug(...)
#endif

#define MAX_N (1000)
#define INF (1LL << 60)
#define eps 1e-9
const int MOD = (int)1e9 + 7;

vector<string> M;

void rec(map<int,vector<int>>& mp, int idx, int depth) {
    for(int i=0; i<depth; i++) cout << ".";
    cout << M[idx] << endl;

    for(int i=0; i<mp[idx].size(); i++){
        rec(mp, mp[idx][i], depth+1);
    }
}

signed main(){
    //ios::sync_with_stdio(false);
    //cin.tie(nullptr);

    int n;
    cin >> n;
    vector<int> k(n);
    M.resize(n);
    for(int i=0; i<n; i++) cin >> k[i] >> M[i];

    map<int, vector<int>> mp;
    for(int i=1; i<n; i++){
        mp[k[i]-1].push_back(i);
    }

    rec(mp, 0, 0);

}

/*

概要：
n個の投稿が与えられる。それぞれは、k_iの投稿への返信とそのメッセージM_iを表す。
k_1は常に０。
返信のツリーを問題文のように作って出力する。

考察：
それぞれの文字列を参照したときにその文字列の子供が分かればいい。
０の文字列は保持しておく。

ハッシュ表に最初の文字列を登録する。
インデックスに該当する文字列をハッシュ表で見つけて、その値に文字列をプッシュする。

ハッシュ表を最初の文字列から深さ優先的に出力していく。


*/
accuracy: 1
time_ms: 10
memory_kb: 3552
final_rank: 11

code_snippet: #include <iostream>
#include <string>
#include <vector>
using namespace std;

void dfs(int i, int d, vector<int> *v, string *s){
    if(i){
        for(int j = 0; j < d; j++) cout << '.';
        cout << s[i] << endl;
    }
    for(int j : v[i]) dfs(j, d + 1, v, s);
}

int main()
{
    int n;
    cin >> n;
    vector<int> v[1002];
    string s[1002];
    for(int i = 1; i <= n; i++){
        int k;
        cin >> k >> s[i];
        v[k].push_back(i);
    }
    dfs(0, -1, v, s);
}
accuracy: 1
time_ms: 10
memory_kb: 3416
final_rank: 4

code_snippet: #include <bits/stdc++.h>
using namespace std;
#define int long long
#define INF 1e18
#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define all(x) (x).begin(), (x).end()
typedef pair<int, int> P;
const int mod = 1000000007;

int n;
vector<int> G[1010];
vector<string> s;

void dfs(int now, int depth){
    rep(i, depth)cout << ".";
    cout << s[now] << endl;

    rep(i, G[now].size()){
        dfs(G[now][i], depth + 1);
    }
}

signed main(){

    cin >> n;
    s.resize(n);
    rep(i, n){
        int k;
        cin >> k >> s[i];
        if(k == 0)continue;
        G[k-1].push_back(i);
    }
    dfs(0, 0);

}
accuracy: 1
time_ms: 10
memory_kb: 3448
final_rank: 6

code_snippet: #include <bits/stdc++.h>
using namespace std;
#define modulo 1000000007
#define mod(mod_x) ((((long long)mod_x+modulo))%modulo)
#define Inf 1000000005

void dfs(vector<vector<int>> &E,vector<string> &S,int now,int d){
	if(now!=0){
		for(int i=0;i<d;i++)cout<<'.';
		cout<<S[now-1]<<endl;
	}
	for(int i=0;i<E[now].size();i++){
		dfs(E,S,E[now][i],d+1);
	}
}

int main(){
	
	int n;
	cin>>n;
	
	vector<vector<int>> children(n+1,vector<int>());
	vector<string> S(n);
	
	for(int i=0;i<n;i++){
		int k;
		cin>>k;
		string s;
		cin>>s;
		S[i] = s;
		children[k].push_back(i+1);
	}
	
	dfs(children,S,0,-1);
		
	return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 3468
final_rank: 9

code_snippet: #include <bits/stdc++.h>
using namespace std;
void dfs(vector<int> &d, vector<string> &M, vector<vector<int>> &c, int v = 0){
  for (int i = 0; i < d[v]; i++){
    cout << '.';
  }
  cout << M[v];
  cout << endl;
  for (int w : c[v]){
    d[w] = d[v] + 1;
    dfs(d, M, c, w);
  }
}
int main(){
  int n;
  cin >> n;
  vector<int> k(n);
  vector<string> M(n);
  for (int i = 0; i < n; i++){
    cin >> k[i] >> M[i];
    k[i]--;
  }
  vector<vector<int>> c(n);
  for (int i = 1; i < n; i++){
    c[k[i]].push_back(i);
  }
  vector<int> d(n);
  d[0] = 0;
  dfs(d, M, c);
}
accuracy: 1
time_ms: 10
memory_kb: 3476
final_rank: 10

code_snippet: #include <bits/stdc++.h>
using namespace std;
#define SZ(x) (int)(x.size())
#define REP(i, n) for(int i=0;i<(n);++i)
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define RREP(i, n) for(int i=(int)(n)-1;i>=0;--i)
#define RFOR(i, a, b) for(int i=(int)(b)-1;i>=(a);--i)
#define ALL(a) a.begin(),a.end()
#define DUMP(x) cerr<<#x<<" = "<<(x)<<endl
#define DEBUG(x) cerr<<#x<<" = "<<(x)<<" (L"<<__LINE__<<")"<< endl;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using P = pair<int, int>;
const double eps = 1e-8;
const ll MOD = 1000000007;
const int INF = INT_MAX / 2;
const ll LINF = LLONG_MAX / 2;
template <typename T1, typename T2>
bool chmax(T1 &a, const T2 &b) {
    if (a < b) { a = b; return true; }
    return false;
}
template <typename T1, typename T2>
bool chmin(T1 &a, const T2 &b) {
    if (a > b) { a = b; return true; }
    return false;
}
template<typename T>
ostream &operator<<(ostream &os, const vector<T> &v) {
    os << "[";
    REP(i, SZ(v)) {
        if (i) os << ", ";
        os << v[i];
    }
    return os << "]";
}
template<typename T1, typename T2>
ostream &operator<<(ostream &os, const map<T1, T2> &mp) {
    os << "{";
    int a = 0;
    for (auto &tp : mp) {
        if (a) os << ", "; a = 1;
        os << tp;
    }
    return os << "}";
}
template<typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p) {
    os << p.first << ":" << p.second;
    return os;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);

    int n; cin >> n;
    vector<string> name(n);
    vvi g(n);
    REP(i, n) {
        int k; cin >> k; --k;
        cin >> name[i];
        if (k == -1) continue;
        g[k].push_back(i);
    }

    function<void(int,int)> dfs = [&](int v, int d) {
        REP(_, d) cout << '.';
        cout << name[v] << endl;
        for (int u : g[v]) {
            dfs(u, d+1);
        }
    };

    dfs(0, 0);


    return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 3464
final_rank: 8

code_snippet: #include <bits/stdc++.h>
using namespace std;

// region template
#define rep(i, a, b) for (int i = (a); i < (b); ++i)
#define trav(a, x) for (auto &a : x)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;

ll gcd(ll a, ll b) { return __gcd(a, b); }

ll euclid(ll a, ll b, ll &x, ll &y) {
    if (b) { ll d = euclid(b, a % b, y, x);
        return y -= a/b * x, d; }
    return x = 1, y = 0, a;
}

typedef unsigned long long ull;
typedef long double ld;
ull mod_mul(ull a, ull b, ull M) {
    ll ret = a * b - M * ull(ld(a) * ld(b) / ld(M));
    return ret + M * (ret < 0) - M * (ret >= (ll)M);
}
ull mod_pow(ull b, ull e, ull mod) {
    ull ans = 1;
    for (; e; b = mod_mul(b, b, mod), e /= 2)
        if (e & 1) ans = mod_mul(ans, b, mod);
    return ans;
}

const ll mod = 1000000007;
struct Mod {
    ll x;
    Mod(ll xx) : x(xx) {}
    Mod operator+(Mod b) { return Mod((x + b.x) % mod); }
    Mod operator-(Mod b) { return Mod((x - b.x) % mod); }
    Mod operator*(Mod b) { return Mod((x * b.x) % mod); }
    Mod operator/(Mod b) { return *this * invert(b); }
    Mod invert(Mod a) {
        ll x, y, g = euclid(a.x, mod, x, y);
        assert(g == 1); return Mod((x + mod) % mod);
    }
    Mod operator^(ll e) {
        if (!e) return Mod(1);
        Mod r = *this ^ (e / 2); r = r * r;
        return e & 1 ? *this * r : r;
    }
};
// endregion

vector<int> childs[1005];
vector<string> msg(1005);

void dfs(int x, int d) {
    rep(i, 0, d) cout << '.';
    cout << msg[x] << endl;
    for (int h : childs[x]) dfs(h, d + 1);
}

int main() {
    
    
    int n; cin >> n;
    rep(i, 1, n + 1) {
        int p; cin >> p;
        childs[p].push_back(i);
        cin >> msg[i];
    }
    dfs(1, 0);

}
accuracy: 1
time_ms: 10
memory_kb: 3388
final_rank: 3

code_snippet: #include <cstdio>
#include <iostream>
#include <string>
#include <sstream>
#include <stack>
#include <algorithm>
#include <cmath>
#include <queue>
#include <map>
#include <set>
#include <cstdlib>
#include <bitset>
#include <tuple>
#include <assert.h>
#include <deque>
#include <bitset>
#include <iomanip>
#include <limits>
#include <chrono>
#include <random>
#include <array>
#include <unordered_map>
#include <functional>
#include <complex>
#include <numeric>
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

constexpr long long MAX = 5100000;
constexpr long long INF = 1LL << 60;
constexpr int inf = 1 << 28;
constexpr long long mod = 1000000007LL;
//constexpr long long mod = 998244353LL;

using namespace std;
typedef unsigned long long ull;
typedef long long ll;

int n;
vector<vector<int>> g;
vector<string> vs;
void dfs(int cur, int p) {
	for (int i = 0; i < p; i++)cout << ".";
	cout << vs[cur] << "\n";
	for (int i = 0; i < g[cur].size(); i++) {
		dfs(g[cur][i], p + 1);
	}
}
int main()
{
	/*
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	*/

	int kkt = 1;
	while (kkt--) {
		scanf("%d", &n);
		g.resize(n);
		vs.resize(n);
		for (int i = 0; i < n; i++) {
			int p; scanf("%d", &p);
			cin >> vs[i];
			if (p != 0) {
				p--;
				g[p].push_back(i);
			}
		}
		dfs(0, 0);
	}
	return 0;

}
accuracy: 1
time_ms: 10
memory_kb: 3456
final_rank: 7

code_snippet: #include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <map>
#include <set>
#include <bitset>
#include <math.h>
#include <stack>
using namespace std;
typedef long long ll;

void solve(int i,int d,vector<pair<string,vector<int>>>v){
	for(int i=0;i<d;i++){
		cout << ".";
	}
	cout << v[i].first << endl;
	for(int t:v[i].second){
		solve(t,d+1,v);
	}
}

int main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	int n; cin >> n;
	vector<pair<string,vector<int>>> v(n);
	for(int i=0;i<n;i++){
		int k; cin >> k;
		cin >> v[i].first;
		if(k){
			v[k-1].second.push_back(i);
		}
	}
	solve(0,0,v);
}
accuracy: 1
time_ms: 40
memory_kb: 66036
final_rank: 20

code_snippet: #include <bits/stdc++.h>
using namespace std;

using ll = long long int;
using ull = unsigned long long int;
using P = pair<ll, ll>;
using P3 = pair<P,ll>;
using PP = pair<P, P>;
constexpr int INF = 1 << 30;
constexpr ll MOD = ll(1e9)+7;
constexpr int di[] = {0, 1, 0, -1};
constexpr int dj[] = {1, 0, -1, 0};
constexpr double EPS = 1e-9;

vector<string> m;
vector<vector<int> > g;
vector<bool> used;

void dfs(int now, int depth=0){
    used[now] = true;
    for(int i=0;i<depth;i++) cout << '.';
    cout << m[now] << endl;
    for(auto nxt:g[now]){
        dfs(nxt, depth+1);
    }
}

int main(){
    int n;
    cin >> n;
    m.resize(n);
    g.resize(n);
    used.resize(n);
    for(int i=0;i<n;i++){
        int k;
        cin >> k >> m[i];
        if(k>0) g[k-1].push_back(i);
    }
    for(int i=0;i<n;i++){
        if(!used[i]) dfs(i);
    }
    return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 3420
final_rank: 5

code_snippet: #include <iostream>
#include <vector>
#include <string>
#include <stack>
#include <utility>

using namespace std;

int main() {
	int n; cin >> n;
	vector<vector<int> > lis(n + 1);
	vector<string> m(n + 1);
	for (int i = 1; i <= n; ++i) {
		int k; cin >> k;
		cin >> m[i];
		lis[k].push_back(i);
	}
	stack<pair<int,int> > st;
	st.push(make_pair(1, 0));
	while (!st.empty()) {
		auto now = st.top(); st.pop();
		for (int i = 0; i < now.second; ++i) cout << ".";
		cout << m[now.first] << endl;
		for (int j = lis[now.first].size() - 1; j >= 0; --j)
			st.push(make_pair(lis[now.first][j], now.second + 1));
	}

	return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 3368
final_rank: 1