C++ Solution || DSU Solution || Detailed Explanation
IntuitionThe problem requires us to find an edge in a graph that, if removed, results in a tree. A tree is an acyclic connected graph, meaning that the addition
# Intuition
The problem requires us to find an edge in a graph that, if removed, results in a tree. A tree is an acyclic connected graph, meaning that the additional edge creates a cycle. The problem can be solved using **Disjoint Set Union (DSU)** or **Union-Find**.

# Approach
1. **Use DSU (Disjoint Set Union)**: We will maintain a **parent** and **size** array to keep track of connected components.
2. **Find the parent of each node**: Using path compression, we efficiently find the representative of the set a node belongs to.
3. **Union by size**: We merge smaller sets into larger ones to keep the DSU operations efficient.
4. **Detect cycle**: If both nodes of an edge have the same parent, then that edge creates a cycle and is the redundant connection.
5. **Return the redundant edge**: The first edge that creates a cycle is our answer.

# Complexity Analysis
- **Time Complexity**: $$O(n \alpha(n))$$, where $$\alpha(n)$$ is the inverse Ackermann function, which is nearly constant.
- **Space Complexity**: $$O(n)$$ for storing the parent and size arrays.

# Code
```cpp
class dsu {
public:
    vector<int> parent, size;
    dsu(int n) {
        parent.resize(n + 1, 0);
        size.resize(n + 1, 1);
        for (int i = 0; i < n; i++) {
            parent[i] = i;
            size[i] = 1;
        }
    }

    int findparent(int node) {
        if (node == parent[node]) {
            return node;
        }
        return parent[node] = findparent(parent[node]); // Path compression
    }

    void unionbysize(int u, int v) {
        int ulp = findparent(u);
        int vlp = findparent(v);
        if (ulp == vlp) return;
        if (size[ulp] < size[vlp]) {
            parent[ulp] = vlp;
            size[vlp] += size[ulp];
        } else {
            parent[vlp] = ulp;
            size[ulp] += size[vlp];
        }
    }
};

class Solution {
public:
    vector<int> findRedundantConnection(vector<vector<int>>& edges) {
        int n = edges.size();
        dsu ds(n);
        for (auto it : edges) {
            if (ds.findparent(it[0]) == ds.findparent(it[1])) {
                return {it[0], it[1]};
            }
            ds.unionbysize(it[0], it[1]);
        }
        return {};
    }
};
```

## Explanation with Example
**Input:**
```cpp
edges = {{1,2}, {1,3}, {2,3}}
```

**Processing:**
1. `1-2` → No cycle, so we union `1` and `2`.
2. `1-3` → No cycle, so we union `1` and `3`.
3. `2-3` → Both nodes belong to the same set → Cycle detected!

**Output:**
```cpp
{2,3}
```

## Edge Cases Considered
- A graph with no redundant connections (already a tree).
- A graph where the last edge forms the cycle.
- A case with multiple cycles (only the first redundant edge is returned).
![d3550b79-52c8-4704-846f-c00daecb5632_1737784461.667478.png](https://assets.leetcode.com/users/images/9ce2f5a5-e187-44e5-842d-82fd8674b37f_1738135817.5696766.png)

['Union Find', 'Graph', 'C++']