#P16780. ⌈Xzy OI R1 T2⌋ 成成边
⌈Xzy OI R1 T2⌋ 成成边
Background
A short and to-the-point statementhow could it be a bad statement.
Problem Description
Given strings . Construct a complete graph with vertices numbered . The weight of edge is defined as , i.e., the length of the longest common prefix of the two strings.
Define the weight of a spanning tree as the sum of the weights of all edges in .
Find the sum of the weights of all spanning trees of , and output the answer modulo .
Input Format
The first line contains an integer . The next lines each contain a string .
Output Format
Output one integer, representing the answer.
3
ab
ac
ad
6
Hint
Sample Explanation
The complete graph has spanning trees, and each tree contains two edges. All three edges have weight , so the sum of edge weights in each tree is , and the total sum is .
Constraints
This problem uses bundled subtasks, which means you must pass all test points in a subtask to get the score for that subtask.
::cute-table{tuack}
| Subtask | Score | Special Restriction | ||
|---|---|---|---|---|
| None | ||||
| ^ | ||||
| All strings are exactly the same | ||||
| ^ | None | |||
For of the testdata, each consists of lowercase letters.
Translated by ChatGPT 5