{"raw_statement":[{"iden":"statement","content":"Peterson loves to learn new languages, but his favorite hobby is making new ones. Language is a set of words, and word is a sequence of lowercase Latin letters.\n\nPeterson makes new language every morning. It is difficult task to store the whole language, so Peterson have invented new data structure for storing his languages which is called broom. Broom is rooted tree with edges marked with letters. Initially broom is represented by the only vertex — the root of the broom. When Peterson wants to add new word to the language he stands at the root and processes the letters of new word one by one. Consider that Peterson stands at the vertex _u_. If there is an edge from _u_ marked with current letter, Peterson goes through this edge. Otherwise Peterson adds new edge from _u_ to the new vertex _v_, marks it with the current letter and goes through the new edge. Size of broom is the number of vertices in it.\n\nIn the evening after working day Peterson can't understand the language he made this morning. It is too difficult for bored Peterson and he tries to make it simpler. Simplification of the language is the process of erasing some letters from some words of this language. Formally, Peterson takes some positive integer _p_ and erases _p_\\-th letter from all the words of this language having length at least _p_. Letters in words are indexed starting by 1. Peterson considers that simplification should change at least one word, i.e. there has to be at least one word of length at least _p_. Peterson tries to make his language as simple as possible, so he wants to choose _p_ such that the size of the broom for his simplified language is as small as possible.\n\nPeterson is pretty annoyed with this task so he asks you for help. Write a program to find the smallest possible size of the broom and integer _p_."},{"iden":"input","content":"The first line of input contains integer _n_ (2 ≤ _n_ ≤ 3·105) — the size of the broom.\n\nNext _n_ - 1 lines describe the broom: _i_\\-th of them contains integers _u__i_, _v__i_ and letter _x__i_ — describing the edge from _u__i_ to _v__i_ marked with letter _x__i_.\n\nVertices are numbered from 1 to _n_. All _x__i_ are lowercase latin letters. Vertex 1 is the root of the broom.\n\nEdges describe correct broom which is made from Peterson's language."},{"iden":"output","content":"The first line of output should contain the minimum possible size of the broom after its simplification. The second line of output should contain integer _p_ to choose. If there are several suitable _p_ values, print the smallest one."},{"iden":"examples","content":"Input\n\n5\n1 2 c\n2 3 a\n3 4 t\n2 5 t\n\nOutput\n\n3\n2\n\nInput\n\n16\n1 2 o\n2 3 f\n1 4 p\n4 5 i\n5 6 e\n6 7 c\n7 8 e\n4 9 r\n9 10 e\n10 11 t\n11 12 t\n12 13 y\n10 14 f\n14 15 i\n15 16 x\n\nOutput\n\n12\n2"},{"iden":"note","content":"![image](https://espresso.codeforces.com/34e91571f3b5d54da921c76053c7a4709d59d1bc.png)\n\nBroom from the second sample test can be built using language \"piece\", \"of\", \"pie\", \"pretty\", \"prefix\". Its simplification with _p_ = 2 obtains the language of words \"pece\", \"o\", \"pe\", \"petty\", \"pefix\". This language gives us the broom with minimum possible size."}],"translated_statement":[{"iden":"statement","content":"Peterson 热爱学习新语言，但他最喜爱的爱好是创造新语言。语言是一组单词的集合，而单词是由小写拉丁字母组成的序列。\n\nPeterson 每天早上都会创造一种新语言。由于存储整个语言很困难，Peterson 发明了一种名为 #cf_span(class=[tex-font-style-underline], body=[broom]) 的新数据结构来存储他的语言。Broom 是一棵边被字母标记的有根树。最初，broom 仅由一个顶点——根组成。当 Peterson 想要向语言中添加一个新单词时，他从根开始，逐个处理单词中的字母。假设 Peterson 当前位于顶点 #cf_span[u]。如果从 #cf_span[u] 出发有一条标记为当前字母的边，Peterson 就沿着这条边移动；否则，他创建一条从 #cf_span[u] 到新顶点 #cf_span[v] 的边，用当前字母标记这条边，并移动到新顶点。Broom 的大小是其中顶点的数量。\n\n在傍晚工作结束后，Peterson 无法理解他早上创造的语言。这对他来说太难了，于是他试图简化它。语言的简化过程是从某些单词中删除一些字母。形式上，Peterson 选择一个正整数 #cf_span[p]，并从所有长度至少为 #cf_span[p] 的单词中删除第 #cf_span[p] 个字母。单词中的字母编号从 1 开始。Peterson 认为简化必须至少改变一个单词，即必须存在至少一个长度至少为 #cf_span[p] 的单词。Peterson 希望让他的语言尽可能简单，因此他希望选择一个 #cf_span[p]，使得简化后语言的 broom 大小最小。\n\nPeterson 对这个任务感到非常烦恼，因此他向你寻求帮助。请编写一个程序，找出最小可能的 broom 大小以及对应的整数 #cf_span[p]。\n\n输入的第一行包含整数 #cf_span[n] (#cf_span[2 ≤ n ≤ 3·105]) —— broom 的大小。\n\n接下来的 #cf_span[n - 1] 行描述 broom：第 #cf_span[i] 行包含整数 #cf_span[ui]、#cf_span[vi] 和字母 #cf_span[xi] —— 描述从 #cf_span[ui] 到 #cf_span[vi] 且标记为字母 #cf_span[xi] 的边。\n\n顶点编号从 1 到 #cf_span[n]。所有 #cf_span[xi] 均为小写拉丁字母。顶点 1 是 broom 的根。\n\n这些边描述了一个由 Peterson 的语言构造出的正确 broom。\n\n输出的第一行应包含简化后 broom 的最小可能大小。第二行应包含要选择的整数 #cf_span[p]。如果有多个合适的 #cf_span[p] 值，请输出最小的那个。\n\n\n\n第二个样例测试中的 broom 可以用语言 \"piece\"、\"of\"、\"pie\"、\"pretty\"、\"prefix\" 构造。其在 #cf_span[p = 2] 下的简化得到语言 \"pece\"、\"o\"、\"pe\"、\"petty\"、\"pefix\"。这个语言给出了最小可能大小的 broom。"},{"iden":"input","content":"输入的第一行包含整数 #cf_span[n] (#cf_span[2 ≤ n ≤ 3·105]) —— broom 的大小。接下来的 #cf_span[n - 1] 行描述 broom：第 #cf_span[i] 行包含整数 #cf_span[ui]、#cf_span[vi] 和字母 #cf_span[xi] —— 描述从 #cf_span[ui] 到 #cf_span[vi] 且标记为字母 #cf_span[xi] 的边。顶点编号从 1 到 #cf_span[n]。所有 #cf_span[xi] 均为小写拉丁字母。顶点 1 是 broom 的根。这些边描述了一个由 Peterson 的语言构造出的正确 broom。"},{"iden":"output","content":"输出的第一行应包含简化后 broom 的最小可能大小。第二行应包含要选择的整数 #cf_span[p]。如果有多个合适的 #cf_span[p] 值，请输出最小的那个。"},{"iden":"examples","content":"输入\n5\n1 2 c\n2 3 a\n3 4 t\n2 5 t\n输出\n3\n2\n\n输入\n16\n1 2 o\n2 3 f\n1 4 p\n4 5 i\n5 6 e\n6 7 c\n7 8 e\n4 9 r\n9 10 e\n10 11 t\n11 12 t\n12 13 y\n10 14 f\n14 15 i\n15 16 x\n输出\n12\n2"},{"iden":"note","content":"第二个样例测试中的 broom 可以用语言 \"piece\"、\"of\"、\"pie\"、\"pretty\"、\"prefix\" 构造。其在 #cf_span[p = 2] 下的简化得到语言 \"pece\"、\"o\"、\"pe\"、\"petty\"、\"pefix\"。这个语言给出了最小可能大小的 broom。"}],"sample_group":[],"show_order":[],"formal_statement":"**Definitions**  \nLet $ T = (V, E) $ be a rooted tree with $ |V| = n $, root at vertex $ 1 $, and each edge $ (u, v) \\in E $ labeled by a lowercase Latin letter.  \nEach root-to-leaf path corresponds to a word in Peterson’s language. Let $ \\mathcal{W} $ be the set of all such words.  \n\nLet $ p \\in \\mathbb{Z}^+ $ be a position (1-indexed) at which Peterson erases the $ p $-th letter from every word $ w \\in \\mathcal{W} $ with $ |w| \\geq p $.  \nLet $ \\mathcal{W}_p = \\{ \\text{delete}(w, p) \\mid w \\in \\mathcal{W}, |w| \\geq p \\} \\cup \\{ w \\mid w \\in \\mathcal{W}, |w| < p \\} $ be the simplified language.  \n\nLet $ B(\\mathcal{W}_p) $ denote the size (number of vertices) of the broom (trie) constructed from $ \\mathcal{W}_p $.  \n\n**Constraints**  \n1. $ 2 \\leq n \\leq 3 \\cdot 10^5 $  \n2. The input tree $ T $ is a valid broom (trie) for some language $ \\mathcal{W} $.  \n3. $ p $ must satisfy: $ \\exists w \\in \\mathcal{W} $ such that $ |w| \\geq p $ (i.e., at least one word is modified).  \n\n**Objective**  \nFind $ p^* \\in \\mathbb{Z}^+ $ minimizing $ B(\\mathcal{W}_p) $, and output:  \n- $ \\min_{p} B(\\mathcal{W}_p) $  \n- the smallest such $ p^* $ achieving this minimum.","simple_statement":null,"has_page_source":false}