Under construction

Still being built. Things may change

Peterson Polyglot

Time limit2sMemory limit512 MB

Summary
Given a trie of words, find the position p whose letter, deleted from every long word, leaves the smallest trie, and print that trie's size.
Level

Medium7 of 10

Topics
Tree, Hash map, String
Solved
No attempts yet

Problem

Peterson loves to learn new languages, but his favorite hobby is making new ones. A language is a set of words, and a word is a sequence of lowercase Latin letters.

Peterson makes a new language every morning. Storing a whole language is hard, so Peterson invented a data structure called a broom to store them. A broom is a rooted tree whose edges are marked with letters. Initially the broom is a single vertex, the root. To add a new word, Peterson starts at the root and processes the letters one by one. Suppose Peterson is at vertex uu. If there is an edge from uu marked with the current letter, he follows that edge. Otherwise he adds a new edge from uu to a new vertex vv, marks it with the current letter, and follows the new edge. The size of a broom is the number of its vertices.

In the evening, Peterson cannot understand the language he made that morning. It is too difficult, so he tries to simplify it. Simplifying a language means erasing some letters from some of its words. Formally, Peterson picks a positive integer pp and erases the pp-th letter from every word whose length is at least pp. Letters are indexed starting from 1. The simplification must change at least one word, so at least one word must have length at least pp. Peterson wants the simplified language to have the smallest possible broom, so he chooses pp to minimize the size of the resulting broom.

Help Peterson find the smallest possible broom size and the integer pp to choose. If several values of pp give the minimum, print the smallest one.

Input

The first line contains an integer nn (2≤n≤3⋅1052 \le n \le 3 \cdot 10^5), the size of the broom. Each of the next n−1n - 1 lines contains integers uiu_i, viv_i and a letter xix_i, describing an edge from uiu_i to viv_i marked with xix_i. Vertices are numbered from 1 to nn, and vertex 1 is the root. Every xix_i is a lowercase Latin letter. The edges describe a valid broom built from Peterson's language.

Output

The first line contains the minimum possible size of the broom after simplification. The second line contains the integer pp to choose. If several suitable values of pp exist, print the smallest one.

Constraints

Let the language consist of words s1,s2,…,sms_1, s_2, \ldots, s_m. Let SS be the total length of the words, that is, S=∑i∣si∣S = \sum_i |s_i|. Let LL be the maximum word length, that is, L=max⁡i∣si∣L = \max_i |s_i|.

Hints

The broom for the language in the second test case can be built from the words "piece", "of", "pie", "pretty", and "prefix". Simplifying it with p=2p = 2 gives the words "pece", "o", "pe", "petty", and "pefix". This language gives the broom with the smallest possible size.

Examples2

  1. Example 1

    Input
    5
    1 2 c
    2 3 a
    3 4 t
    2 5 t
    
    Expected output
    3
    2
    
  2. Example 2

    Input
    16
    1 2 o
    2 3 f
    1 4 p
    4 5 i
    5 6 e
    6 7 c
    7 8 e
    4 9 r
    9 10 e
    10 11 t
    11 12 t
    12 13 y
    10 14 f
    14 15 i
    15 16 x
    
    Expected output
    12
    2