#C9758. Balanced Tree Verification

    ID: 53886 Type: Default 1000ms 256MiB

Balanced Tree Verification

Balanced Tree Verification

You are given a weighted, undirected tree with N vertices and N-1 edges. Each edge has an associated weight. The tree is considered balanced if all edge weights are identical.

In other words, given the weights \(w_1, w_2, \dots, w_{N-1}\) of the edges, the tree is balanced if and only if \[ w_1 = w_2 = \cdots = w_{N-1}. \]

Note: For a tree with only 2 vertices (and hence 1 edge), the tree is always considered balanced.

Your task is to determine whether the given tree is balanced. Print Yes if it is balanced, or No otherwise.

inputFormat

The first line contains an integer N (N ≥ 2), representing the number of vertices in the tree.

The following N-1 lines each contain three integers u v w, indicating there is an edge between vertices u and v with weight w.

outputFormat

Output a single line containing either Yes if the tree is balanced or No if it is not.

## sample
3
1 2 3
2 3 3
Yes