atcoder#ABC173F. [ABC173F] Intervals on Tree
[ABC173F] Intervals on Tree
Score : points
Problem Statement
We have a tree with vertices and edges, respectively numbered and . Edge connects Vertex and .
For integers (), let us define a function as follows:
- Let be the set of the vertices numbered through . represents the number of connected components in the subgraph formed only from the vertex set and the edges whose endpoints both belong to .
Compute .
Constraints
- The given graph is a tree.
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
Output
Print .
3
1 3
2 3
7
We have six possible pairs as follows:
- For , and we have connected component.
- For , and we have connected components.
- For , and we have connected component, since contains both endpoints of each of the edges .
- For , and we have connected component.
- For , and we have connected component, since contains both endpoints of Edge .
- For , and we have connected component.
The sum of these is .
2
1 2
3
10
5 3
5 7
8 9
1 9
9 10
8 4
7 4
6 10
7 2
113