Monk in the real estate
Practice
3.3 (234 votes)
Ad Hoc
Easy
Graphs
Open
Problem
92% Success 34177 Attempts 20 Points 1s Time Limit 256MB Memory 1024 KB Max Code

The Monk wants to buy some cities. To buy two cities, he needs to buy the road connecting those two cities. Now, you are given a list of roads, bought by the Monk. You need to tell how many cities did the Monk buy.

Input:
First line contains an integer T, denoting the number of test cases. The first line of each test case contains an integer E, denoting the number of roads. The next E lines contain two space separated integers X and Y, denoting that there is an road between city X and city Y.

Output:
For each test case, you need to print the number of cities the Monk bought.

Constraint:
1 <= T <= 100
1 <= E <= 1000
1 <= X, Y <= 10000

Please login to use the editor

You need to be logged in to access the code editor

Loading...

Please wait while we load the editor

Loading...
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
Points:20
254 votes
Tags:
ApprovedEasyGraphsOpenTrees
Points:20
3 votes
Tags:
GraphsReal worldGraph RepresentationData StructuresAlgorithms
Points:20
34 votes
Tags:
AlgorithmsEasyGraphs