#K77052. Count Direct Communication Pairs in a Tree
Count Direct Communication Pairs in a Tree
Count Direct Communication Pairs in a Tree
A tree is an undirected, connected graph with no cycles. In this problem, you are given a tree consisting of n nodes and n-1 edges. Each edge represents a direct communication link between two nodes. Your task is to count the number of unique direct communication pairs in the tree.
Since every edge in a tree implies a direct connection between two nodes, the answer is simply the number of edges. Mathematically, if the number of nodes is \(n\), then the number of unique direct communication pairs is given by:
\(n - 1\)
Note that the tree is given in the form of a list of edges.
inputFormat
The input is given from stdin and it has the following format:
- The first line contains an integer n representing the number of nodes in the tree.
- The next n - 1 lines each contain two space-separated integers u and v representing an edge between nodes u and v.
outputFormat
Output a single integer to stdout which represents the number of unique direct communication pairs (i.e. the number of edges in the tree).
## sample4
1 2
1 3
3 4
3