Finding pairs
Practice
2.6 (18 votes)
Algorithms
Depth first search
Graphs
Problem
89% Success 3252 Attempts 20 Points 1s Time Limit 256MB Memory 1024 KB Max Code
You are given a rooted tree with
You have to find the number of pairs
Input format
- The first line contains
denoting the integer. - Next
lines denote the edges of the tree.
Output format
Print a single integer denoting the number of pairs
Constraints
Sample Input
4 1 2 2 3 3 4
Sample Output
10
Explanation
All pairs follow the given condition: (1, 1), (1, 2), (1, 3), (1, 4), (2, 2), (2, 3), (2, 4), (3, 3), (3, 4), (4, 4).
Code Editor
Please login to use the editor
You need to be logged in to access the code editor
Submissions
Please login to view your submissions
Similar Problems
Points:20
39 votes
Tags:
AlgorithmsApprovedBreadth First SearchEasyGraphsOpen
Points:20
121 votes
Tags:
ApprovedEasyMathNumber theory
Points:20
66 votes
Tags:
ApprovedDepth First SearchDisjoint setEasyGraphsOpen
Editorial
Login to unlock the editorial
Please login to use the editor
You need to be logged in to access the code editor