# Redundant Connection - I

Posted: 25 Mar, 2021
Difficulty: Moderate

## PROBLEM STATEMENT

#### Example:

`````` Let’s say we have 3 edges that are {1 , 2} , {1 , 3} and {2 , 3}. So
the resulting graph from these edges will be :
1
/ \
2 - 3

If we remove the edge {2, 3} then the resulting graph will be a tree with N nodes.
``````
##### Input format:
``````The very first line of input contains an integer ‘T’ denoting the number of test cases.

The first line of every test case contains an integer ‘N’ denoting the number of nodes of the graph.

The second line of every test case contains a 2d array 'ARR' of NX2 size, which contains N edges of the graph.
``````
##### Output format:
``````For each test case, return that single edge that if removed, the resulting graph will be a tree of N nodes.

Output for each test case is printed on a separate line.
``````
##### Note:
``````You do not need to print anything, it has already been taken care of. Just return an edge that can be removed so that the resulting graph is a tree of N nodes.

If there are multiple answers, return the answer that occurs last in the given 2D array ARR of size NX2. The answer edge [u, v] should be in the same format, with u < v.
``````
##### Constraints:
``````1 <= T <= 10
3 <= N <= 10^3
1 <= ARR[i] <= N

Time Limit: 1 sec
`````` Approach 1

Approach:

• This is basically the brute force approach.
• The idea is to use one edge less from the end each time and to check whether it can make the graph to break into two connected components.
• Also for ease, we can store the edges in zero-based indexing.

Algorithm:

• Take an integer variable ‘N’  equal to the size of the edges array ‘ARR’.
• Also, store the value of ‘N’ into ‘M’
• Now till N not equal to 1 do the following steps: