#P10165. [DTCPC 2024] 人赢的跳棋
[DTCPC 2024] 人赢的跳棋
Background
Little C is the one who always wins.
Every Wednesday night, Little T is eating pork trotter rice, while Little C is having dinner with a girl in the cafeteria.
Every Friday night, Little T starts up the Ruins Library, while Little C is chatting with a girl.
Today, Little T is sleeping, and Little C is playing checkers that humans always win with a girl.
Problem Description
Given a tree with vertices. Each edge has a weight, and the weight is a triple. The triple of the -th edge is .
Define the function :
- If and , then .
- If and , then .
- Otherwise, .
Here and .
Obviously, the function is commutative.
For a triple sequence , define its value as . In particular, when , its value is .
Define the value of a path as the value of the sequence formed by the weights of all edges on the path in order.
Compute the sum of values over all undirected paths in the tree.
Input Format
The first line contains a positive integer (), denoting the number of vertices in the tree.
The next lines each contain four integers , where .
It is guaranteed that are pairwise distinct, and are pairwise distinct. Their values are all in .
Output Format
Output one integer on one line, denoting the answer.
5
1 2 1 2
1 3 2 1
1 4 3 3
1 5 4 4
9
7
1 2 3 4
2 3 6 2
2 4 1 3
2 5 4 6
3 6 2 1
5 7 5 5
44
Hint
One set of hack testdata was added on 2025/10/31.
Translated by ChatGPT 5