GUPTA MECHANICAL

IN THIS WEBSITE I CAN TELL ALL ABOUT TECH. TIPS AND TRICKS APP REVIEWS AND UNBOXINGS ALSO TECH. NEWS .............

Monday 23 May 2022

[Solution] Unique Occurrences Codeforces Solution | Codeforces Problem Solution 2022

F. Unique Occurrences
time limit per test
6 seconds
memory limit per test
1024 megabytes
input
standard input
output
standard output

You are given a tree, consisting of n vertices. Each edge has an integer value written on it.

Let f(v,u) be the number of values that appear exactly once on the edges of a simple path between vertices v and u.

Solution Click Below:-  CLICK HERE

Calculate the sum of f(v,u) over all pairs of vertices v and u such that 1v<un.

Input

The first line contains a single integer n (2n5105) — the number of vertices in the tree.

Each of the next n1 lines contains three integers v,u and x (1v,u,xn) — the description of an edge: the vertices it connects and the value written on it.

The given edges form a tree.

Output

Print a single integer — the sum of f(v,u) over all pairs of vertices v and u such that v<u.


No comments:

Post a Comment