# Redundant Connection - II

Posted: 27 Mar, 2021

Difficulty: Moderate

#### You are given a directed graph that starts as a rooted tree with 'N' nodes (with distinct values from 1 to 'N'), with one additional directed edge added. The added edge has two different vertices chosen from 1 to ‘N’ and was not an edge that already existed.

#### The resulting graph is given as a 2D-array of edges. Each element of edges is a pair ['Ui', 'Vi'] that represents a directed edge connecting nodes ‘Ui’ and ‘Vi’, where ‘Ui’ is a parent of the child ‘Vi’.

#### Your task is to find and return that single edge that if removed, the resulting graph will be a tree of 'N' nodes.

#### Note:

```
1. A rooted tree is a directed graph such that, there is exactly one node (the root) for which all other nodes are descendants of this node, plus every node has exactly one parent, except for the root node which has no parents.
2. If there are multiple answers, return the answer that occurs last in the given 2D-array. The answer edge [u, v] should be in the same format, with u < v.
```

##### 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 :
```

```
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 of 'N' X 2 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:

```
1. 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.
```

##### Constraints:

```
1 <= T <= 10
3 <= N <= 1000
1 <= 'ARR[i]' <= N
Where ‘ARR[i]’ represents the edges of the graph.
Time Limit: 1 sec
```

SIMILAR PROBLEMS

Minimum Swaps To Make Identical Array

Posted: 22 Jan, 2022

Difficulty: Moderate

Find Center of Star Graph

Posted: 26 Jan, 2022

Difficulty: Easy

Critical Connections in a Network

Posted: 27 Jan, 2022

Difficulty: Hard

Critical Connections in a Network

Posted: 27 Jan, 2022

Difficulty: Hard

Good Bad Graph

Posted: 26 May, 2022

Difficulty: Hard

COUNT ISLANDS

Posted: 14 Sep, 2022

Difficulty: Moderate