QOJ.ac

QOJ

时间限制: 5 s 内存限制: 512 MB 总分: 100 可 Hack ✓

#1491. sone3

统计

Given a tree with $n$ nodes, each edge is labeled with a lowercase letter.

Let $str(x,y)$ denote the string formed by the characters on the simple path from $x$ to $y$ in the tree.

A string $T$ is defined as "excellent" if and only if $T$ can be represented in the form $SS$, where $S$ is any non-empty string.

Calculate the number of distinct excellent strings that exist in the tree.

Input

The first line contains a positive integer $n$ ($2 \leq n \leq 5 \times 10^4$), representing the number of nodes in the tree.

The next $n-1$ lines each contain $x, y, c$, representing an edge connecting $(x, y)$ with the lowercase letter $c$ on it.

Output

Output a non-negative integer representing the answer.

Examples

Input 1

5
1 2 a
2 3 a
3 4 b
4 5 b

Output 1

2

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.