Unique Occurrences solution codeforces
Unique Occurrences solution codeforces You are given a tree, consisting of nn vertices. Each edge has an integer value written on it. Let f(v,u)f(v,u) be the number of values that appear exactly once on the edges of a simple path between vertices vv and uu. Calculate the sum of f(v,u)f(v,u) over all pairs of vertices vv and uu such that 1≤v<u≤n1≤v<u≤n. Input The first line contains a single integer nn (2≤n≤5⋅1052≤n≤5⋅105) — the number …