#P10333. [UESTCPC 2024] 打字
[UESTCPC 2024] 打字
Problem Description
You are given a trie with nodes, rooted at node . For every other node, the edge from its parent to it has a character, and for nodes with the same parent, these characters are all different. The path from the root to each node represents a word, formed by concatenating the characters on the path in order. Each node has a weight , meaning the word represented by this node needs to be written times.
You have a cache, and you may choose any number of words to store in the cache. When writing a word, typing one character costs . After finishing a complete word, you may choose to end the current word and start spelling the next word. The cache will, based on the characters you have already typed, suggest the lexicographically smallest word in the cache that has this typed string as a prefix. At this time, you may pay cost to directly output this word, and end the spelling of the current word, then start spelling the next word. Note that a string is also considered a prefix of itself.
Find the minimum total cost to finish spelling all words on the trie.
Input Format
The first line contains three integers , representing the size of the trie, the cost to type one character, and the cost to output a word using the cache.
Then follow lines. On the -th line, the input first contains two integers , representing the weight on node and the number of children of node . Then follow integers , representing the indices of the children of node , given in increasing lexicographical order of the characters on the edges from node to these children.
It is guaranteed that .
Output Format
Output one integer in one line, representing the minimum cost to finish spelling all words on the trie.
4 2 3
0 2 3 2
3 0
2 1 4
4 0
22
Hint
[Sample Explanation]
Assume the children of each node are encoded as in increasing lexicographical order. The optimal strategy is to put into the cache. Then can be typed using suggestions at a cost of , while and are typed directly. The total cost is .
Translated by ChatGPT 5